codeparrot/xlcost-text-to-code huggingface dataset:
Numbers having Unique ( or Distinct ) digits | C # implementation to find unique digit numbers in a range ; Method to print unique digit numbers in range from l to r . ; Start traversing the numbers ; Find digits and maintain its hash ; if a digit occurs more than 1 time then break ; num will be 0 only when above loop doesn 't get  break that means the number  is unique so print it. ; Driver method
using System ; public class GFG { static void printUnique ( int l , int r ) { for ( int i = l ; i <= r ; i ++ ) { int num = i ; bool [ ] visited = new bool [ 10 ] ; while ( num != 0 ) { if ( visited [ num % 10 ] ) break ; visited [ num % 10 ] = true ; num = num / 10 ; } if ( num == 0 ) Console . Write ( i + " ▁ " ) ; } } public static void Main ( ) { int l = 1 , r = 20 ; printUnique ( l , r ) ; } }
Fibonacci modulo p | C # program to find minimal 0 Fibonacci for a prime number p ; Function that returns position of first Fibonacci number whose modulo p is 0 ; add previous two remainders and then take its modulo p . ; Driver program
using System ; class GFG { static int findMinZero ( int p ) { int first = 1 , second = 1 ; int number = 2 , next = 1 ; while ( next > 0 ) { next = ( first + second ) % p ; first = second ; second = next ; number ++ ; } return number ; } public static void Main ( ) { int p = 7 ; Console . WriteLine ( " Minimal ▁ zero ▁ " + " is ▁ : " + findMinZero ( p ) ) ; } }
Perfect cubes in a range | A Simple Method to count cubes between a and b ; Traverse through all numbers in given range and one by one check if number is prime ; Check if current number ' i ' is perfect cube ; Driver method
using System ; class GFG { static void printCubes ( int a , int b ) { for ( int i = a ; i <= b ; i ++ ) { for ( int j = 1 ; j * j * j <= i ; j ++ ) { if ( j * j * j == i ) { Console . Write ( j * j * j + " ▁ " ) ; break ; } } } } public static void Main ( ) { int a = 1 , b = 100 ; Console . WriteLine ( " Perfect ▁ cubes ▁ in " + " ▁ given ▁ range : " ) ; printCubes ( a , b ) ; } }
Converting a Real Number ( between 0 and 1 ) to Binary String | C # program to Binary real number to String . ; Main function to convert Binary real number to String ; Check Number is Between 0 to 1 or Not ; Setting a limit on length : 32 characters , If the number cannot be represented accurately in binary with at most 32 characters ; It compare the number to . 5. ; Now it become 0.25 ; Driver Code ; double num1 = 0.625 ; Input value in Decimal
using System ; class BinaryToString { static string printBinary ( double num ) { if ( num >= 1 num <= 0 ) return " ERROR " ; string binary = " " ; double frac = 0.5 ; binary += " . " ; while ( num > 0 ) { if ( binary . Length >= 32 ) return " ERROR " ; if ( num >= frac ) { binary += "1" ; num -= frac ; } else binary += "0" ; frac /= 2 ; } return binary ; } public static void Main ( ) { String output = printBinary ( num1 ) ; Console . WriteLine ( " ( 0" + output + " ) ▁ in ▁ base ▁ 2" ) ; double num2 = 0.72 ; output = printBinary ( num2 ) ; Console . WriteLine ( " ( " + output + " ) ▁ " ) ; } }
Given a number n , find the first k digits of n ^ n | C # program to find the first k digits of n ^ n ; function that manually calculates n ^ n and then removes digits until k digits remain ; loop will terminate when there are only k digits left ; Driver code
using System ; class Digits { static long firstkdigits ( int n , int k ) { long product = 1 ; for ( int i = 0 ; i < n ; i ++ ) product *= n ; while ( ( int ) ( product / Math . Pow ( 10 , k ) ) != 0 ) product = product / 10 ; return product ; } public static void Main ( ) { int n = 15 ; int k = 4 ; Console . Write ( firstkdigits ( n , k ) ) ; } }
Check if a large number is divisible by 9 or not | C # program to find if a number is divisible by 9 or not . ; Function to find that number is divisible by 9 or not ; Compute sum of digits ; Check if sum of digits is divisible by 9. ; main function
using System ; class GFG { static bool check ( String str ) { int n = str . Length ; int digitSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) digitSum += ( str [ i ] - '0' ) ; return ( digitSum % 9 == 0 ) ; } public static void Main ( ) { String str = "99333" ; if ( check ( str ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
XOR of all subarray XORs | Set 1 | C # program to get total XOR of all subarray xors ; Returns XOR of all subarray xors ; initialize result by 0 as ( a xor 0 = a ) ; select the starting element ; select the eNding element ; Do XOR of elements in current subarray ; Driver Code
using System ; class GFG { static int getTotalXorOfSubarrayXors ( int [ ] arr , int N ) { int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = i ; j < N ; j ++ ) for ( int k = i ; k <= j ; k ++ ) res = res ^ arr [ k ] ; return res ; } static void Main ( ) { int [ ] arr = { 3 , 5 , 2 , 4 , 6 } ; int N = arr . Length ; Console . Write ( getTotalXorOfSubarrayXors ( arr , N ) ) ; } }
XOR of all subarray XORs | Set 1 | C # program to get total xor of all subarray xors ; Returns XOR of all subarray xors ; initialize result by 0 as ( a XOR 0 = a ) ; loop over all elements once ; get the frequency of current element ; if frequency is odd , then include it in the result ; return the result ; Driver Code
using System ; class GFG { static int getTotalXorOfSubarrayXors ( int [ ] arr , int N ) { int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int freq = ( i + 1 ) * ( N - i ) ; if ( freq % 2 == 1 ) res = res ^ arr [ i ] ; } return res ; } public static void Main ( ) { int [ ] arr = { 3 , 5 , 2 , 4 , 6 } ; int N = arr . Length ; Console . Write ( getTotalXorOfSubarrayXors ( arr , N ) ) ; } }
GCD of more than two ( or array ) numbers | C # program to find GCD of two or more numbers ; Function to return gcd of a and b ; Function to find gcd of array of numbers ; Driver Code
using System ; public class GCD { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int findGCD ( int [ ] arr , int n ) { int result = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { result = gcd ( arr [ i ] , result ) ; if ( result == 1 ) { return 1 ; } } return result ; } public static void Main ( ) { int [ ] arr = { 2 , 4 , 6 , 8 , 16 } ; int n = arr . Length ; Console . Write ( findGCD ( arr , n ) ) ; } }
Superperfect Number | C # program to check whether number is superperfect or not ; Function to calculate sum of all divisors ; Final result of summation of divisors ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Returns true if n is Super Perfect else false . ; Find the sum of all divisors of number n ; Again find the sum of all divisors of n1 and check if sum is equal to n1 ; Driver code
using System ; class Divisors { static int divSum ( int num ) { int result = 0 ; for ( int i = 1 ; i * i <= num ; ++ i ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return result ; } static bool isSuperPerfect ( int n ) { int n1 = divSum ( n ) ; return ( 2 * n == divSum ( n1 ) ) ; } public static void Main ( ) { int n = 16 ; Console . WriteLine ( ( isSuperPerfect ( n ) ? " Yes " : " No " ) ) ; n = 6 ; Console . WriteLine ( ( isSuperPerfect ( n ) ? " Yes " : " No " ) ) ; } }
Refactorable number | C # program to check whether number is refactorable or not ; Function to count all divisors ; Initialize result ; If divisors are equal , count only one . ; Otherwise count both ; Driver code
using System ; class GFG { static bool isRefactorableNumber ( int n ) { int divCount = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( n ) ; ++ i ) { if ( n % i == 0 ) { if ( n / i == i ) ++ divCount ; else divCount += 2 ; } } return n % divCount == 0 ; } public static void Main ( ) { int n = 8 ; if ( isRefactorableNumber ( n ) ) Console . WriteLine ( " yes " ) ; else Console . Write ( " no " ) ; n = 14 ; if ( isRefactorableNumber ( n ) ) Console . Write ( " yes " ) ; else Console . Write ( " no " ) ; } }
Count all perfect divisors of a number | C # code to count total perfect Divisors ; Utility function to check perfect square number ; Returns count all perfect divisors of n ; Initialize result ; Consider every number that can be a divisor of n ; If i is a divisor ; Driver code
using System ; class GFG { static bool isPerfectSquare ( int n ) { int sq = ( int ) Math . Sqrt ( n ) ; return ( n == sq * sq ) ; } static int countPerfectDivisors ( int n ) { int count = 0 ; for ( int i = 1 ; i * i <= n ; ++ i ) { if ( n % i == 0 ) { if ( isPerfectSquare ( i ) ) ++ count ; if ( n / i != i && isPerfectSquare ( n / i ) ) ++ count ; } } return count ; } static public void Main ( ) { int n = 16 ; Console . Write ( " Total ▁ perfect ▁ " + " divisors ▁ of ▁ " + n ) ; Console . WriteLine ( " ▁ = ▁ " + countPerfectDivisors ( n ) ) ; n = 12 ; Console . Write ( " Total ▁ perfect ▁ " + " divisors ▁ of ▁ " + n ) ; Console . WriteLine ( " ▁ = ▁ " + countPerfectDivisors ( n ) ) ; } }
Nearest element with at | C # program to print nearest element with at least one common prime factor . ; Loop covers the every element of arr [ ] ; Loop that covers from 0 to i - 1 and i + 1 to n - 1 indexes simultaneously ; print position of closest element ; Recursive function to return gcd of a and b ; Driver code
using System ; class GFG { static void nearestGcd ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; ++ i ) { int closest = - 1 ; for ( int j = i - 1 , k = i + 1 ; j > 0 k <= n ; -- j , ++ k ) { if ( j >= 0 && __gcd ( arr [ i ] , arr [ j ] ) > 1 ) { closest = j + 1 ; break ; } if ( k < n && __gcd ( arr [ i ] , arr [ k ] ) > 1 ) { closest = k + 1 ; break ; } } Console . Write ( closest + " ▁ " ) ; } } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void Main ( ) { int [ ] arr = { 2 , 9 , 4 , 3 , 13 } ; int n = arr . Length ; nearestGcd ( arr , n ) ; } }
Largest subsequence having GCD greater than 1 | Efficient C # program to find length of the largest subsequence with GCD greater than 1. ; prime [ ] for storing smallest prime divisor of element count [ ] for storing the number of times a particular divisor occurs in a subsequence ; Simple sieve to find smallest prime factors of numbers smaller than MAX ; Prime number will have same divisor ; Returns length of the largest subsequence with GCD more than 1. ; Fetch total unique prime divisor of element ; Increment count [ ] of Every unique divisor we get till now ; Find maximum frequency of divisor ; Driver code ; Pre - compute smallest divisor of all numbers
using System ; class GFG { static int MAX = 100001 ; static int [ ] prime = new int [ MAX + 1 ] ; static int [ ] countdiv = new int [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { for ( int i = 2 ; i * i <= MAX ; ++ i ) { if ( prime [ i ] == 0 ) for ( int j = i * 2 ; j <= MAX ; j += i ) prime [ j ] = i ; } for ( int i = 1 ; i < MAX ; ++ i ) if ( prime [ i ] == 0 ) prime [ i ] = i ; } static int largestGCDSubsequence ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int element = arr [ i ] ; while ( element > 1 ) { int div = prime [ element ] ; ++ countdiv [ div ] ; ans = Math . Max ( ans , countdiv [ div ] ) ; while ( element % div == 0 ) element /= div ; } } return ans ; } public static void Main ( ) { SieveOfEratosthenes ( ) ; int [ ] arr = { 10 , 15 , 7 , 25 , 9 , 35 } ; int size = arr . Length ; Console . WriteLine ( largestGCDSubsequence ( arr , size ) ) ; } }
Count of Binary Digit numbers smaller than N | C # program to count all binary digit numbers smaller than N ; method returns count of binary digit numbers smaller than N ; queue to store all intermediate binary digit numbers ; binary digits start with 1 ; loop until we have element in queue ; push next binary digit numbers only if current popped element is N ; uncomment below line to print actual number in sorted order ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int countOfBinaryNumberLessThanN ( int N ) { Queue < int > q = new Queue < int > ( ) ; q . Enqueue ( 1 ) ; int cnt = 0 ; int t ; while ( q . Count > 0 ) { t = q . Peek ( ) ; q . Dequeue ( ) ; if ( t <= N ) { cnt ++ ; q . Enqueue ( t * 10 ) ; q . Enqueue ( t * 10 + 1 ) ; } } return cnt ; } static void Main ( ) { int N = 200 ; Console . WriteLine ( countOfBinaryNumberLessThanN ( N ) ) ; } }
Sum of product of x and y such that floor ( n / x ) = y | C # program to find sum of product of x and y such that n / x = y ( Integer Division ) ; Return the sum of product x * y . ; Iterating x from 1 to n ; Finding y = n / x . ; Adding product of x and y to answer . ; Driver Code
using System ; class GFG { static int sumofproduct ( int n ) { int ans = 0 ; for ( int x = 1 ; x <= n ; x ++ ) { int y = n / x ; ans += ( y * x ) ; } return ans ; } static public void Main ( String [ ] args ) { int n = 10 ; Console . WriteLine ( sumofproduct ( n ) ) ; } }
Program for Perrin numbers | Optimized C # program for n 'th perrin number ; Driver code
using System ; class GFG { static int per ( int n ) { int a = 3 , b = 0 , c = 2 ; int m = 0 ; if ( n == 0 ) return a ; if ( n == 1 ) return b ; if ( n == 2 ) return c ; while ( n > 2 ) { m = a + b ; a = b ; b = c ; c = m ; n -- ; } return m ; } public static void Main ( ) { int n = 9 ; Console . WriteLine ( per ( n ) ) ; } }
Find the first natural number whose factorial is divisible by x | C # program for finding the Special Factorial Number ; function for calculating factorial ; function for check Special_Factorial_Number ; call fact function and the Modulo with k and check if condition is TRUE then return i ; driver function ; taking input
using System ; public class GFG { static int fact ( int n ) { int num = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { num = num * i ; } return num ; } static int Special_Factorial_Number ( int k ) { for ( int i = 1 ; i <= k ; i ++ ) { if ( fact ( i ) % k == 0 ) { return i ; } } return 0 ; } public static void Main ( ) { int k = 16 ; Console . WriteLine ( Special_Factorial_Number ( k ) ) ; } }
Program for Chocolate and Wrapper Puzzle | Efficient C # program to find maximum number of chocolates ; Returns maximum number of chocolates we can eat with given money , price of chocolate and number of wrapprices required to get a chocolate . ; Corner case ; First find number of chocolates that can be purchased with the given amount ; Now just add number of chocolates with the chocolates gained by wrapprices ; Driver code ; total money ; cost of each candy ; no of wrappers needs to be ; exchanged for one chocolate .
using System ; class GFG { static int countMaxChoco ( int money , int price , int wrap ) { if ( money < price ) return 0 ; int choc = money / price ; choc = choc + ( choc - 1 ) / ( wrap - 1 ) ; return choc ; } public static void Main ( ) { int money = 15 ; int price = 1 ; int wrap = 3 ; Console . WriteLine ( countMaxChoco ( money , price , wrap ) ) ; } }
Check if possible to move from given coordinate to desired coordinate | C # program to check if it is possible to reach ( a , b ) from ( x , y ) . ; Returns GCD of i and j ; Returns true if it is possible to go to ( a , b ) from ( x , y ) ; Find absolute values of all as sign doesn 't matter. ; If gcd is equal then it is possible to reach . Else not possible . ; Driver code ; Converting coordinate into positive integer
using System ; class GFG { static int gcd ( int i , int j ) { if ( i == j ) return i ; if ( i > j ) return gcd ( i - j , j ) ; return gcd ( i , j - i ) ; } static bool ispossible ( int x , int y , int a , int b ) { x = Math . Abs ( x ) ; y = Math . Abs ( y ) ; a = Math . Abs ( a ) ; b = Math . Abs ( b ) ; return ( gcd ( x , y ) == gcd ( a , b ) ) ; } public static void Main ( ) { int x = 35 , y = 15 ; int a = 20 , b = 25 ; if ( ispossible ( x , y , a , b ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Equidigital Numbers | C # program to find Equidigital Numbers till n ; Array to store all prime less than and equal to MAX . ; Utility function for sieve of sundaram ; In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than MAX , we reduce MAX to half This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j ; Main logic of Sundaram . Mark all numbers which do not generate prime number by doing 2 * i + 1 ; Since 2 is a prime number ; Print other primes . Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false . ; Returns true if n is a Equidigital number , else false . ; Count digits in original number ; Count all digits in prime factors of n pDigit is going to hold this value . ; Count powers of p in n ; If primes [ i ] is a prime factor , ; Count the power of prime factors ; Add its digits to pDigit . ; Add digits of power of prime factors to pDigit . ; If n != 1 then one prime factor still to be summed up ; ; If digits in prime factors and digits in original number are same , then return true . Else return false . ; Driver method ; Finding all prime numbers before limit . These numbers are used to find prime factors .
using System ; using System . Collections ; public class GFG { static int MAX = 10000 ; static ArrayList primes = new ArrayList ( MAX + 1 ) ; static void sieveSundaram ( ) { bool [ ] marked = new bool [ MAX / 2 + 1 ] ; for ( int i = 1 ; i <= ( Math . Sqrt ( MAX ) - 1 ) / 2 ; i ++ ) for ( int j = ( i * ( i + 1 ) ) << 1 ; j <= MAX / 2 ; j = j + 2 * i + 1 ) marked [ j ] = true ; primes . Add ( 2 ) ; for ( int i = 1 ; i <= MAX / 2 ; i ++ ) if ( marked [ i ] == false ) primes . Add ( 2 * i + 1 ) ; } static bool isEquidigital ( int n ) { if ( n == 1 ) return true ; int original_no = n ; int sumDigits = 0 ; while ( original_no > 0 ) { sumDigits ++ ; original_no = original_no / 10 ; } int pDigit = 0 , count_exp = 0 , p = 0 ; for ( int i = 0 ; ( int ) primes [ i ] <= n / 2 ; i ++ ) { while ( n % ( int ) primes [ i ] == 0 ) { p = ( int ) primes [ i ] ; n = n / p ; count_exp ++ ; } while ( p > 0 ) { pDigit ++ ; p = p / 10 ; } while ( count_exp > 1 ) { pDigit ++ ; count_exp = count_exp / 10 ; } } if ( n != 1 ) { while ( n > 0 ) { pDigit ++ ; n = n / 10 ; } } return ( pDigit == sumDigits ) ; } public static void Main ( ) { sieveSundaram ( ) ; Console . WriteLine ( " Printing ▁ first ▁ few ▁ Equidigital ▁ Numbers ▁ using ▁ isEquidigital ( ) " ) ; for ( int i = 1 ; i < 20 ; i ++ ) if ( isEquidigital ( i ) ) Console . Write ( i + " ▁ " ) ; } }
Maximum sum of distinct numbers with LCM as N | C # program to get maximum sum of Numbers with condition that their LCM should be N ; Method returns maximum sum f distinct number whose LCM is N ; Find all divisors which divides ' N ' ; if ' i ' is divisor of ' N ' ; if both divisors are same then add it only once else add both ; Driver code
using System ; class GFG { static int getMaximumSumWithLCMN ( int N ) { int sum = 0 ; int LIM = ( int ) Math . Sqrt ( N ) ; for ( int i = 1 ; i <= LIM ; i ++ ) { if ( N % i == 0 ) { if ( i == ( N / i ) ) sum += i ; else sum += ( i + N / i ) ; } } return sum ; } public static void Main ( ) { int N = 12 ; Console . Write ( getMaximumSumWithLCMN ( N ) ) ; } }
LCM of First n Natural Numbers | C # program to find LCM of First N Natural Numbers . ; to calculate hcf ; to calculate lcm ; lcm ( a , b ) = ( a * b ) / hcf ( a , b ) ; assign a = lcm of n , n - 1 ; b = b - 1 ; Driver code ; base case ; Function call pass n , n - 1 in function to find LCM of first n natural number
using System ; class GFG { static int hcf ( int a , int b ) { if ( b == 0 ) return a ; return hcf ( b , a % b ) ; } static int findlcm ( int a , int b ) { if ( b == 1 ) return a ; a = ( a * b ) / hcf ( a , b ) ; b -= 1 ; return findlcm ( a , b ) ; } static void Main ( ) { int n = 7 ; if ( n < 3 ) Console . Write ( n ) ; else Console . Write ( findlcm ( n , n - 1 ) ) ; } }
Smallest number divisible by first n numbers | C # program to find smallest number evenly divisible by all numbers 1 to n ; Function for gcd ; Function returns the lcm of first n numbers ; Driver program to test the above function
using System ; public class GFG { static long gcd ( long a , long b ) { if ( a % b != 0 ) return gcd ( b , a % b ) ; else return b ; } static long lcm ( long n ) { long ans = 1 ; for ( long i = 1 ; i <= n ; i ++ ) ans = ( ans * i ) / ( gcd ( ans , i ) ) ; return ans ; } static public void Main ( ) { long n = 20 ; Console . WriteLine ( lcm ( n ) ) ; } }
Trapezoidal Rule for Approximate Value of Definite Integral | C # program to implement Trapezoidal rule . ; A sample function whose definite integral 's approximate value  is computed using Trapezoidal  rule ; Declaring the function f ( x ) = 1 / ( 1 + x * x ) ; Function to evaluate the value of integral ; Grid spacing ; Computing sum of first and last terms in above formula ; Adding middle terms in above formula ; h / 2 indicates ( b - a ) / 2 n . Multiplying h / 2 with s . ; Driver code ; Range of definite integral ; Number of grids . Higher value means more accuracy
using System ; class GFG { static float y ( float x ) { return 1 / ( 1 + x * x ) ; } static float trapezoidal ( float a , float b , float n ) { float h = ( b - a ) / n ; float s = y ( a ) + y ( b ) ; for ( int i = 1 ; i < n ; i ++ ) s += 2 * y ( a + i * h ) ; return ( h / 2 ) * s ; } public static void Main ( ) { float x0 = 0 ; float xn = 1 ; int n = 6 ; Console . Write ( " Value ▁ of ▁ integral ▁ is ▁ " + Math . Round ( trapezoidal ( x0 , xn , n ) * 10000.0 ) / 10000.0 ) ; } }
Breaking an Integer to get Maximum Product |  ; The main function that returns the max possible product ; n equals to 2 or 3 must be handled explicitly ; Keep removing parts of size 3 while n is greater than 4 ; Keep multiplying 3 to res ; The last part multiplied by previous parts ; Driver code
using System ; class GFG { static int maxProd ( int n ) { if ( n == 2 n == 3 ) return ( n - 1 ) ; int res = 1 ; while ( n > 4 ) { n -= 3 ; res *= 3 ; } return ( n * res ) ; } static void Main ( ) { Console . WriteLine ( " Maximum ▁ Product ▁ is ▁ " + maxProd ( 45 ) ) ; } }
Finding number of digits in n 'th Fibonacci number | C # program to find number of digits in nth Fibonacci number ; This function returns the number of digits in nth Fibonacci number after ceiling it Formula used ( n * log ( phi ) - ( log 5 ) / 2 ) ; using phi = 1.6180339887498948 ; Driver code
using System ; class GFG { static double numberOfDigits ( double n ) { if ( n == 1 ) return 1 ; double d = ( n * Math . Log10 ( 1.6180339887498948 ) ) - ( ( Math . Log10 ( 5 ) ) / 2 ) ; return Math . Ceiling ( d ) ; } public static void Main ( ) { double i ; for ( i = 1 ; i <= 10 ; i ++ ) Console . WriteLine ( " Number ▁ of ▁ Digits ▁ in ▁ F ( " + i + " ) ▁ - ▁ " + numberOfDigits ( i ) ) ; } }
Number of elements with odd factors in given range | C # program to count number of odd squares in given range [ n , m ] ; Function to count odd squares ; Driver code
using System ; class GFG { public static int countOddSquares ( int n , int m ) { return ( int ) Math . Pow ( ( double ) m , 0.5 ) - ( int ) Math . Pow ( ( double ) n - 1 , 0.5 ) ; } public static void Main ( ) { int n = 5 , m = 100 ; Console . Write ( " Count ▁ is ▁ " + countOddSquares ( n , m ) ) ; } }