codeparrot/xlcost-text-to-code huggingface dataset:
Sum of series 1 * 1 ! + 2 * 2 ! + …… . . + n * n ! | C # program to find sum of the series . ; Function to calculate required series ; Driver code
using System ; class GFG { static int factorial ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int calculateSeries ( int n ) { return factorial ( n + 1 ) - 1 ; } static public void Main ( ) { int n = 3 ; Console . WriteLine ( calculateSeries ( n ) ) ; } }
Sum of series 1 * 1 * 2 ! + 2 * 2 * 3 ! + …… . . + n * n * ( n + 1 ) ! | C # program to find sum of the series . ; Function to calculate required series ; Driver code
using System ; class GFG { static int factorial ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int calculateSeries ( int n ) { return 2 + ( n * n + n - 2 ) * factorial ( n + 1 ) ; } public static void Main ( ) { int n = 3 ; Console . WriteLine ( calculateSeries ( n ) ) ; } }
Aspiring Number | C # implementation to check whether a number is aspiring or not ; Function to calculate sum of all proper divisors ; Note that this loop runs till square root of n ; If divisors are equal , take only one of them ; else Otherwise take both ; calculate sum of all proper divisors only ; Function to get last number of Aliquot Sequence . ; Calculate next term from previous term ; Returns true if n is perfect ; To store sum of divisors ; Find all divisors and add them ; If sum of divisors is equal to n , then n is a perfect number ; Returns true if n is aspiring else returns false ; checking condition for aspiring ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int getSum ( int n ) { for ( int i = 1 ; i <= ( int ) Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { sum = sum + i ; } { sum = sum + i ; sum = sum + ( n / i ) ; } } } return sum - n ; } static int getAliquot ( int n ) { HashSet < int > s = new HashSet < int > ( ) ; s . Add ( n ) ; while ( n > 0 ) { n = getSum ( n ) ; if ( s . Contains ( n ) ) { return n ; } s . Add ( n ) ; } return 0 ; } static bool isPerfect ( int n ) { int sum = 1 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { sum = sum + i + n / i ; } } if ( sum == n && n != 1 ) { return true ; } return false ; } static bool isAspiring ( int n ) { int alq = getAliquot ( n ) ; if ( isPerfect ( alq ) && ! isPerfect ( n ) ) { return true ; } else { return false ; } } public static void Main ( String [ ] args ) { int n = 25 ; if ( isAspiring ( n ) ) { Console . WriteLine ( " Aspiring " ) ; } else { Console . WriteLine ( " Not ▁ Aspiring " ) ; } } }
Forming smallest array with given constraints | C # program to find the length of smallest array begin with x , having y , ends with z and having absolute difference between adjacent elements <= 1. ; Return the size of smallest array with given constraint . ; Driver Code
using System ; class GFG { static int minimumLength ( int x , int y , int z ) { return 1 + Math . Abs ( x - y ) + Math . Abs ( y - z ) ; } public static void Main ( ) { int x = 3 , y = 1 , z = 2 ; Console . WriteLine ( minimumLength ( x , y , z ) ) ; } }
Find the other | C # program to find the other - end point of diameter ; function to find the other - end point of diameter ; find end point for x coordinates ; find end point for y coordinates ; Driver Code
using System ; class GFG { static void endPointOfDiameterofCircle ( int x1 , int y1 , int c1 , int c2 ) { Console . Write ( " x2 ▁ = ▁ " + ( 2 * c1 - x1 ) + " ▁ " ) ; Console . Write ( " y2 ▁ = ▁ " + ( 2 * c2 - y1 ) ) ; } public static void Main ( ) { int x1 = - 4 , y1 = - 1 ; int c1 = 3 , c2 = 5 ; endPointOfDiameterofCircle ( x1 , y1 , c1 , c2 ) ; } }
Newton 's Divided Difference Interpolation Formula | C # program for implementing Newton divided difference formula ; Function to find the product term ; Function for calculating divided difference table ; Function for applying Newton 's  divided difference formula  ; Function for displaying divided difference table ; Driver Function ; number of inputs given ; y [ ] [ ] is used for divided difference table where y [ ] [ 0 ] is used for input ; calculating divided difference table ; displaying divided difference table ; value to be interpolated ; printing the value
using System ; class GFG { static float proterm ( int i , float value , float [ ] x ) { float pro = 1 ; for ( int j = 0 ; j < i ; j ++ ) { pro = pro * ( value - x [ j ] ) ; } return pro ; } static void dividedDiffTable ( float [ ] x , float [ , ] y , int n ) { for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < n - i ; j ++ ) { y [ j , i ] = ( y [ j , i - 1 ] - y [ j + 1 , i - 1 ] ) / ( x [ j ] - x [ i + j ] ) ; } } } static float applyFormula ( float value , float [ ] x , float [ , ] y , int n ) { float sum = y [ 0 , 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { sum = sum + ( proterm ( i , value , x ) * y [ 0 , i ] ) ; } return sum ; } static void printDiffTable ( float [ , ] y , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n - i ; j ++ ) { Console . Write ( Math . Round ( y [ i , j ] , 4 ) + " TABSYMBOL ▁ " ) ; } Console . WriteLine ( " " ) ; } } public static void Main ( ) { int n = 4 ; float value ; float [ , ] y = new float [ 10 , 10 ] ; float [ ] x = { 5 , 6 , 9 , 11 } ; y [ 0 , 0 ] = 12 ; y [ 1 , 0 ] = 13 ; y [ 2 , 0 ] = 14 ; y [ 3 , 0 ] = 16 ; dividedDiffTable ( x , y , n ) ; printDiffTable ( y , n ) ; value = 7 ; Console . WriteLine ( " STRNEWLINE Value ▁ at ▁ " + ( value ) + " ▁ is ▁ " + Math . Round ( applyFormula ( value , x , y , n ) , 2 ) ) ; } }
Centered heptagonal number | C # program to find n - th Centered heptagonal number ; Function to find Centered heptagonal number ; Formula to calculate nth Centered heptagonal number ; Driver Code
using System ; class GFG { static long centered_heptagonal_num ( long n ) { return ( 7 * n * n - 7 * n + 2 ) / 2 ; } public static void Main ( ) { long n = 5 ; Console . WriteLine ( n + " th ▁ Centered ▁ " + " heptagonal ▁ number ▁ : ▁ " + centered_heptagonal_num ( n ) ) ; } }
Sum of square | C # Program to find the sum of sum of squares of first n natural number ; Function to find sum of sum of square of first n natural number ; Driver Program
using System ; public class GFG { static int findSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += ( ( i * ( i + 1 ) * ( 2 * i + 1 ) ) / 6 ) ; return sum ; } static public void Main ( ) { int n = 3 ; Console . WriteLine ( findSum ( n ) ) ; } }
Check if a given matrix is Hankel or not | C # Program to check if given matrix is Hankel Matrix or not . ; Function to check if given matrix is Hankel Matrix or not . ; for each row ; for each column ; checking if i + j is less than n ; checking if the element is equal to the corresponding diagonal constant ; checking if the element is equal to the corresponding diagonal constant ; Drivers code
using System ; class GFG { static bool checkHankelMatrix ( int n , int [ , ] m ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i + j < n ) { if ( m [ i , j ] != m [ i + j , 0 ] ) return false ; } else { if ( m [ i , j ] != m [ i + j - n + 1 , n - 1 ] ) return false ; } } } return true ; } public static void Main ( ) { int n = 4 ; int [ , ] m = { { 1 , 2 , 3 , 5 } , { 2 , 3 , 5 , 8 } , { 3 , 5 , 8 , 0 } , { 5 , 8 , 0 , 9 } } ; if ( checkHankelMatrix ( n , m ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Check if a number can be expressed as power | Set 2 ( Using Log ) | C # program to find if a number can be expressed as x raised to power y . ; Find Log n in different bases and check if the value is an integer ; Driver Code
using System ; class GFG { static bool isPower ( int n ) { for ( int x = 2 ; x <= ( int ) Math . Sqrt ( n ) ; x ++ ) { float f = ( float ) Math . Log ( n ) / ( float ) Math . Log ( x ) ; if ( ( f - ( int ) f ) == 0.0 ) return true ; } return false ; } public static void Main ( ) { for ( int i = 2 ; i < 100 ; i ++ ) if ( isPower ( i ) ) Console . Write ( i + " ▁ " ) ; } }
Queries on sum of odd number digit sums of all the factors of a number | C # Program to answer queries on sum of sum of odd number digits of all the factors of a number ; finding sum of odd digit number in each integer . ; for each number ; using previous number sum , finding the current number num of odd digit also , adding last digit if it is odd . ; finding sum of sum of odd digit of all the factors of a number . ; for each possible factor ; adding the contribution . ; Wrapper function ; Driver code
using System ; class GFG { static int N = 1000005 ; static void sumOddDigit ( int [ ] digitSum ) { for ( int i = 1 ; i < N ; i ++ ) { digitSum [ i ] = digitSum [ i / 10 ] + ( i & 1 ) * ( i % 10 ) ; } } static void sumFactor ( int [ ] digitSum , int [ ] factorDigitSum ) { for ( int i = 1 ; i < N ; i ++ ) { for ( int j = i ; j < N ; j += i ) { factorDigitSum [ j ] += digitSum [ i ] ; } } } static void wrapper ( int q , int [ ] n ) { int [ ] digitSum = new int [ N ] ; int [ ] factorDigitSum = new int [ N ] ; sumOddDigit ( digitSum ) ; sumFactor ( digitSum , factorDigitSum ) ; for ( int i = 0 ; i < q ; i ++ ) Console . Write ( factorDigitSum [ n [ i ] ] + " ▁ " ) ; } public static void Main ( ) { int q = 2 ; int [ ] n = new int [ ] { 10 , 36 } ; wrapper ( q , n ) ; } }
Program for Gauss | C # Implementation for Gauss - Jordan Elimination Method ; Function to print the matrix ; function to reduce matrix to reduced row echelon form . ; Performing elementary operations ; Excluding all i == j ; Converting Matrix to reduced row echelon form ( diagonal matrix ) ; Function to print the desired result if unique solutions exists , otherwise prints no solution or infinite solutions depending upon the input given . ; Printing the solution by dividing constants by their respective diagonal elements ; To check whether infinite solutions exists or no solution exists ; flag == 2 for infinite solution flag == 3 for No solution ; Driver code ; Order of Matrix ( n ) ; Performing Matrix transformation ; Printing Final Matrix ; Printing Solutions ( if exist )
using System ; using System . Collections . Generic ; class GFG { static int M = 10 ; static void PrintMatrix ( float [ , ] a , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) Console . Write ( a [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } static int PerformOperation ( float [ , ] a , int n ) { int i , j , k = 0 , c , flag = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i , i ] == 0 ) { c = 1 ; while ( ( i + c ) < n && a [ i + c , i ] == 0 ) c ++ ; if ( ( i + c ) == n ) { flag = 1 ; break ; } for ( j = i , k = 0 ; k <= n ; k ++ ) { float temp = a [ j , k ] ; a [ j , k ] = a [ j + c , k ] ; a [ j + c , k ] = temp ; } } for ( j = 0 ; j < n ; j ++ ) { if ( i != j ) { float p = a [ j , i ] / a [ i , i ] ; for ( k = 0 ; k <= n ; k ++ ) a [ j , k ] = a [ j , k ] - ( a [ i , k ] ) * p ; } } } return flag ; } static void PrintResult ( float [ , ] a , int n , int flag ) { Console . Write ( " Result ▁ is ▁ : ▁ " ) ; if ( flag == 2 ) Console . WriteLine ( " Infinite ▁ Solutions ▁ Exists " ) ; else if ( flag == 3 ) Console . WriteLine ( " No ▁ Solution ▁ Exists " ) ; else { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( a [ i , n ] / a [ i , i ] + " ▁ " ) ; } } static int CheckConsistency ( float [ , ] a , int n , int flag ) { int i , j ; float sum ; flag = 3 ; for ( i = 0 ; i < n ; i ++ ) { sum = 0 ; for ( j = 0 ; j < n ; j ++ ) sum = sum + a [ i , j ] ; if ( sum == a [ i , j ] ) flag = 2 ; } return flag ; } public static void Main ( String [ ] args ) { float [ , ] a = { { 0 , 2 , 1 , 4 } , { 1 , 1 , 2 , 6 } , { 2 , 1 , 1 , 7 } } ; int n = 3 , flag = 0 ; flag = PerformOperation ( a , n ) ; if ( flag == 1 ) flag = CheckConsistency ( a , n , flag ) ; Console . WriteLine ( " Final ▁ Augumented ▁ Matrix ▁ is ▁ : ▁ " ) ; PrintMatrix ( a , n ) ; Console . WriteLine ( " " ) ; PrintResult ( a , n , flag ) ; } }
Number of digits in the nth number made of given four digits | C # program to count number of digits in n - th number made of given four digits . ; Efficient function to calculate number of digits in the nth number constructed by using 6 , 1 , 4 and 9 as digits in the ascending order . ; Number of digits increase after every i - th number where i increases in powers of 4. ; Driver Code
using System ; public class GFG { static int number_of_digits ( int n ) { int i ; int res ; int sum = 0 ; for ( i = 4 , res = 1 ; ; i *= 4 , res ++ ) { sum += i ; if ( sum >= n ) break ; } return res ; } static public void Main ( ) { int n = 21 ; Console . WriteLine ( number_of_digits ( n ) ) ; } }
Print prime numbers from 1 to N in reverse order | C # program to print all primes between 1 to N in reverse order using Sieve of Eratosthenes ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Print all prime numbers ; Driver code ; static input ; To display ; calling the function
using System ; class GFG { static void reverseorder ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int i = n ; i >= 2 ; i -- ) if ( prime [ i ] == true ) Console . Write ( i + " ▁ " ) ; } public static void Main ( ) { int N = 25 ; Console . WriteLine ( " Prime ▁ number ▁ in " + " ▁ reverse ▁ order " ) ; if ( N == 1 ) Console . WriteLine ( " No ▁ prime ▁ no " + " ▁ exist ▁ in ▁ this ▁ range " ) ; else reverseorder ( N ) ; } }
Vantieghems Theorem for Primality Test | C # code to verify Vantieghem 's Theorem ; Check if above condition is satisfied ; product of previous powers of 2 ; Driver code
using System ; class GFG { static void checkVantieghemsTheorem ( int limit ) { long prod = 1 ; for ( long n = 2 ; n < limit ; n ++ ) { if ( ( ( prod - n < 0 ? 0 : prod - n ) % ( ( 1 << ( int ) n ) - 1 ) ) == 0 ) Console . Write ( n + " ▁ is ▁ prime STRNEWLINE " ) ; prod *= ( ( 1 << ( int ) n ) - 1 ) ; } } public static void Main ( ) { checkVantieghemsTheorem ( 10 ) ; } }
Count numbers formed by given two digit with sum having given digits | C # program to count the number of numbers formed by digits a and b exactly of a length N such that the sum of the digits of the number thus formed is of digits a and b . ; function to check if sum of digits is made of a and b ; sum of digits is 0 ; if any of digits in sum is other than a and b ; calculate the modInverse V / of a number in O ( log n ) ; q is quotient ; m is remainder now , process same as Euclid 's algo ; Update y and x ; Make x positive ; function to pregenerate factorials ; function to pre calculate the modInverse of factorials ; calculates the modInverse of the last factorial ; precalculates the modInverse of all factorials by formulae ; function that returns the value of nCi ; function that returns the count of numbers ; function call to pre - calculate the factorials and modInverse of factorials ; if a and b are same ; Driver Code
using System ; class GFG { static int mod = ( int ) ( 1e9 + 7 ) ; static int N = 1000005 ; static int [ ] fact = new int [ N ] ; static int [ ] invfact = new int [ N ] ; static int check ( int x , int a , int b ) { if ( x == 0 ) { return 0 ; } while ( x > 0 ) { if ( x % 10 != a & x % 10 != b ) { return 0 ; } x /= 10 ; } return 1 ; } static int modInverse ( int a , int m ) { int m0 = m ; int y = 0 , x = 1 ; if ( m == 1 ) { return 0 ; } while ( a > 1 ) { int q = a / m ; int t = m ; m = a % m ; a = t ; t = y ; y = x - q * y ; x = t ; } if ( x < 0 ) { x += m0 ; } return x ; } static void pregenFact ( ) { fact [ 0 ] = fact [ 1 ] = 1 ; for ( int i = 1 ; i <= 1000000 ; ++ i ) { fact [ i ] = ( int ) ( ( long ) fact [ i - 1 ] * i % mod ) ; } } static void pregenInverse ( ) { invfact [ 0 ] = invfact [ 1 ] = 1 ; invfact [ 1000000 ] = modInverse ( fact [ 1000000 ] , mod ) ; for ( int i = 999999 ; i > 1 ; -- i ) { invfact [ i ] = ( int ) ( ( ( long ) invfact [ i + 1 ] * ( long ) ( i + 1 ) ) % mod ) ; } } static int comb ( int big , int small ) { return ( int ) ( ( long ) fact [ big ] * invfact [ small ] % mod * invfact [ big - small ] % mod ) ; } static int count ( int a , int b , int n ) { pregenFact ( ) ; pregenInverse ( ) ; if ( a == b ) { return ( check ( a * n , a , b ) ) ; } int ans = 0 ; for ( int i = 0 ; i <= n ; ++ i ) { if ( check ( i * a + ( n - i ) * b , a , b ) == 1 ) { ans = ( ans + comb ( n , i ) ) % mod ; } } return ans ; } public static void Main ( String [ ] args ) { int a = 3 , b = 4 , n = 11028 ; Console . WriteLine ( count ( a , b , n ) ) ; } }
Finding n | C # Program to Finding n - th term of series 3 , 13 , 42 , 108 , 235 . . . ; Function to generate a fixed number ; Driver Code
using System ; class GFG { public static int magicOfSequence ( int N ) { int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) sum += ( i * i * i + i * 2 ) ; return sum ; } static public void Main ( ) { int N = 4 ; Console . WriteLine ( magicOfSequence ( N ) ) ; } }
Expressing a number as sum of consecutive | Set 2 ( Using odd factors ) | C # program to count number of ways to express N as sum of consecutive numbers . ; returns the number of odd factors ; If i is an odd factor and n is a perfect square ; If n is not perfect square ; Driver Code ; N as sum of consecutive numbers
using System ; class GFG { static int countOddFactors ( long n ) { int odd_factors = 0 ; for ( int i = 1 ; 1 * i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( 1 * i * i == n ) { if ( ( i & 1 ) == 1 ) odd_factors ++ ; } else { if ( ( i & 1 ) == 1 ) odd_factors ++ ; int factor = ( int ) n / i ; if ( ( factor & 1 ) == 1 ) odd_factors ++ ; } } } return odd_factors - 1 ; } static void Main ( ) { long N = 15 ; Console . WriteLine ( countOddFactors ( N ) ) ; N = 10 ; Console . WriteLine ( countOddFactors ( N ) ) ; } }
Making zero array by decrementing pairs of adjacent | C # program to find if it is possible to make all array elements 0 by decrement operations . ; used for storing the sum of even and odd position element in array . ; if position is odd , store sum value of odd position in odd ; if position is even , store sum value of even position in even ; Driver Code
using System ; class GFG { static bool isPossibleToZero ( int [ ] a , int n ) { int even = 0 , odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( i & 1 ) == 0 ) odd += a [ i ] ; else even += a [ i ] ; } return ( odd == even ) ; } static public void Main ( ) { int [ ] arr = { 0 , 1 , 1 , 0 } ; int n = arr . Length ; if ( isPossibleToZero ( arr , n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Program for sum of cos ( x ) series | C # program to find the sum of cos ( x ) series ; here x is in degree . we have to convert it to radian for using it with series formula , as in series expansion angle is in radian ; Driver Code
using System ; class GFG { static double PI = 3.142 ; static double cosXSertiesSum ( double x , int n ) { x = x * ( PI / 180.0 ) ; double res = 1 ; double sign = 1 , fact = 1 , pow = 1 ; for ( int i = 1 ; i < 5 ; i ++ ) { sign = sign * - 1 ; fact = fact * ( 2 * i - 1 ) * ( 2 * i ) ; pow = pow * x * x ; res = res + sign * pow / fact ; } return res ; } public static void Main ( ) { float x = 50 ; int n = 5 ; Console . Write ( ( float ) ( cosXSertiesSum ( x , n ) * 1000000 ) / 1000000.00 ) ; } }
Sum of digits written in different bases from 2 to n | Java program to find the sum of digits of n in different base1s from 2 to n - 1. ; function to calculate sum of digit for a given base1 ; Sum of digits ; Calculating the number ( n ) by taking mod with the base1 and adding remainder to the result and parallelly reducing the num value . ; returning the result ; function calling for multiple base1s ; Driver Code
using System ; class GFG { static int solve ( int n , int base1 ) { int result = 0 ; while ( n > 0 ) { int remainder = n % base1 ; result = result + remainder ; n = n / base1 ; } return result ; } static void printSumsOfDigits ( int n ) { for ( int base1 = 2 ; base1 < n ; ++ base1 ) Console . Write ( solve ( n , base1 ) + " ▁ " ) ; } public static void Main ( ) { int n = 8 ; printSumsOfDigits ( n ) ; } }
Possible two sets from first N natural numbers difference of sums as D | C # program for implementing above approach ; Function returns true if it is possible to split into two sets otherwise returns false ; Driver code
using System ; class GFG { static bool check ( int N , int D ) { int temp = ( N * ( N + 1 ) ) / 2 + D ; return ( temp % 2 == 0 ) ; } static public void Main ( ) { int N = 5 ; int M = 7 ; if ( check ( N , M ) ) Console . Write ( " yes " ) ; else Console . Write ( " no " ) ; } }
Minimum digits to remove to make a number Perfect Square | C # program to find required minimum digits need to remove to make a number perfect square ; function to check minimum number of digits should be removed to make this number a perfect square ; size of the string ; our final answer ; to store string which is perfect square . ; We make all possible subsequences ; to check jth bit is set or not . ; we do not consider a number with leading zeros ; convert our temporary string into integer ; checking temp is perfect square or not . ; taking maximum sized string ; print PerfectSquare ; Driver code
using System ; class GFG { static int perfectSquare ( string s ) { int n = s . Length ; int ans = - 1 ; string num = " " ; for ( int i = 1 ; i < ( 1 << n ) ; i ++ ) { string str = " " ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( ( i >> j ) & 1 ) == 1 ) { str += s [ j ] ; } } if ( str [ 0 ] != '0' ) { int temp = 0 ; for ( int j = 0 ; j < str . Length ; j ++ ) temp = temp * 10 + ( int ) ( str [ j ] - '0' ) ; int k = ( int ) Math . Sqrt ( temp ) ; if ( k * k == temp ) { if ( ans < ( int ) str . Length ) { ans = ( int ) str . Length ; num = str ; } } } } if ( ans == - 1 ) return ans ; else { Console . Write ( num + " ▁ " ) ; return n - ans ; } } public static void Main ( ) { Console . WriteLine ( perfectSquare ( "8314" ) ) ; Console . WriteLine ( perfectSquare ( "753" ) ) ; } }
Lagrange 's four square theorem | C # program for Lagrange 's four square identity ; Prints all the possible combinations 4 numbers whose sum of squares is equal to the given no . ; loops checking the sum of squares ; if sum of four squares equals the given no . ; printing the numbers ; Driver code ; 74 = 0 * 0 + 0 * 0 + 5 * 5 + 7 * 7 74 = 0 * 0 + 1 * 1 + 3 * 3 + 8 * 8 74 = 0 * 0 + 3 * 3 + 4 * 4 + 7 * 7 74 = 1 * 1 + 1 * 1 + 6 * 6 + 6 * 6 74 = 2 * 2 + 3 * 3 + 5 * 5 + 6 * 6
using System ; class GFG { static void printFourSquares ( int a ) { for ( int i = 0 ; i * i <= a ; i ++ ) { for ( int j = i ; j * j <= a ; j ++ ) { for ( int k = j ; k * k <= a ; k ++ ) { for ( int l = k ; l * l <= a ; l ++ ) { if ( i * i + j * j + k * k + l * l == a ) { Console . Write ( a + " ▁ = ▁ " + i + " * " + i + " ▁ + ▁ " + j + " * " + j + " ▁ + ▁ " ) ; Console . Write ( k + " * " + k + " ▁ + ▁ " + l + " * " + l + " STRNEWLINE " ) ; } } } } } } public static void Main ( ) { int a = 74 ; printFourSquares ( a ) ; } }
Hardy | C # program to count all prime factors ; A function to count prime factors of a given number n ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; This condition is to handle the case when n is a prime number greater than 2 ; Driver function
using System ; class GFG { static int exactPrimeFactorCount ( int n ) { int count = 0 ; if ( n % 2 == 0 ) { count ++ ; while ( n % 2 == 0 ) n = n / 2 ; } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { count ++ ; while ( n % i == 0 ) n = n / i ; } } if ( n > 2 ) count ++ ; return count ; } public static void Main ( ) { int n = 51242183 ; Console . WriteLine ( " The ▁ number ▁ of " + " ▁ distinct ▁ prime ▁ factors ▁ is / are ▁ " + exactPrimeFactorCount ( n ) ) ; Console . WriteLine ( " The ▁ value ▁ of ▁ " + " log ( log ( n ) ) ▁ is ▁ " + Math . Log ( Math . Log ( n ) ) ) ; } }