codeparrot/xlcost-text-to-code huggingface dataset:
Min steps to convert N | C # program for the above problem ; Adjacency list for numbers till 100001 ; Visited array ; To store distance of every vertex from A ; Function to check if number is a prime ; Function to check if numbers differ by only a single - digit ; Check the last digit of both numbers and increase count if different ; Generate all N digit primes ; For every prime number i check if an edge can be made . ; For every prime number i check if an edge can be made from i to j . ; If edge is possible then insert in the adjacency list ; Function to count distance ; If unvisited push onto queue and mark visited as 1 and add the distance of curr + 1. ; Driver code ; Call bfs traversal with root as node A ; Indicates not possible
using System ; using System . Collections . Generic ; class GFG { static List < List < int > > lis = new List < List < int > > ( ) ; static List < int > primes = new List < int > ( ) ; static int [ ] vis = new int [ 100001 ] ; static int [ ] dis = new int [ 100001 ] ; static bool isPrime ( int n ) { int i = 2 ; while ( i * i <= n ) { if ( n % i == 0 ) return false ; i += 1 ; } return true ; } static bool valid ( int a , int b ) { int c = 0 ; while ( a > 0 ) { if ( ( a % 10 ) != ( b % 10 ) ) c += 1 ; a = a / 10 ; b = b / 10 ; } if ( c == 1 ) return true ; else return false ; } static void makePrimes ( int N ) { int L = ( int ) Math . Pow ( 10 , N - 1 ) ; int R = ( int ) Math . Pow ( 10 , N ) - 1 ; for ( int i = L ; i < R + 1 ; i ++ ) { if ( isPrime ( i ) ) primes . Add ( i ) ; } for ( int i = 0 ; i < primes . Count ; i ++ ) { for ( int j = i + 1 ; j < primes . Count ; j ++ ) { int a = primes [ i ] ; int b = primes [ j ] ; if ( valid ( a , b ) ) { lis [ a ] . Add ( b ) ; lis [ b ] . Add ( a ) ; } } } } static void bfs ( int src ) { List < int > q = new List < int > ( ) ; q . Add ( src ) ; vis [ src ] = 1 ; dis [ src ] = 0 ; while ( q . Count != 0 ) { int curr = q [ 0 ] ; q . RemoveAt ( 0 ) ; foreach ( int x in lis [ curr ] ) { if ( vis [ x ] == 0 ) { vis [ x ] = 1 ; q . Add ( x ) ; dis [ x ] = dis [ curr ] + 1 ; } } } } static void Main ( ) { for ( int i = 0 ; i < 100001 ; i ++ ) { lis . Add ( new List < int > ( ) ) ; } int N = 4 ; makePrimes ( N ) ; int A = 1033 ; int B = 8179 ; bfs ( A ) ; if ( dis [ B ] == - 1 ) { Console . Write ( - 1 ) ; } else { Console . Write ( dis [ B ] ) ; } } }
Place Value of a given digit in a number | C # implementation to find place value of a number ; function to find place value ; Driver Code ; Digit , which we want to find place value . ; Number from where we want to find place value .
using System ; class GFG { static int placeValue ( int N , int num ) { int total = 1 , value = 0 , rem = 0 ; while ( true ) { rem = N % 10 ; N = N / 10 ; if ( rem == num ) { value = total * rem ; break ; } total = total * 10 ; } return value ; } public static void Main ( ) { int D = 5 ; int N = 85932 ; Console . Write ( placeValue ( N , D ) ) ; } }
Super | C # implementation to check if N is a super Poulet number ; Function to find the divisors ; Loop to iterate over the square root of the N ; Check if divisors are equal ; Function to check if N is a super Poulet number ; Loop to check that every divisor divides 2 ^ D - 2 ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < int > findDivisors ( int n ) { List < int > divisors = new List < int > ( ) ; for ( int i = 1 ; i < ( Math . Sqrt ( n ) + 1 ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) divisors . Add ( i ) ; else { divisors . Add ( i ) ; divisors . Add ( ( n / i ) ) ; } } } divisors . Sort ( ) ; return divisors ; } static bool isSuperdNum ( int n ) { List < int > d = findDivisors ( n ) ; foreach ( int i in d ) { double x = ( Math . Pow ( 2 , i ) - 2 ) / i ; if ( Math . Truncate ( x ) != x ) return false ; } return true ; } public static void Main ( string [ ] args ) { int n = 341 ; if ( isSuperdNum ( n ) == true ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Beatty sequence | C # implementation of the above approach ; Function to print the first N terms of the Beatty sequence ; Driver code
using System ; class GFG { static void BeattySequence ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { double ans = Math . Floor ( i * Math . Sqrt ( 2 ) ) ; Console . Write ( ans + " , ▁ " ) ; } } public static void Main ( ) { int n = 5 ; BeattySequence ( n ) ; } }
Primitive Abundant Number | C # implementation of the above approach ; Function to sum of divisors ; Note that this loop runs till square root of N ; If divisors are equal , take only one of them ; Otherwise take both ; Function to check Abundant Number ; Return true if sum of divisors is greater than N . ; Function to check Deficient Number ; Check if sum ( n ) < 2 * n ; Function to check all proper divisors of N is deficient number or not ; If number itself is not abundant retuen false ; 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 ; Driver Code
using System ; class GFG { static int getSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) sum = sum + i ; else { sum = sum + i ; sum = sum + ( n / i ) ; } } } return sum ; } static bool checkAbundant ( int n ) { return ( getSum ( n ) - n > n ) ; } static bool isDeficient ( int n ) { return ( getSum ( n ) < ( 2 * n ) ) ; } static bool checkPrimitiveAbundant ( int num ) { if ( ! checkAbundant ( num ) ) { return false ; } for ( int i = 2 ; i <= Math . Sqrt ( num ) ; i ++ ) { if ( num % i == 0 && i != num ) { if ( i * i == num ) { if ( ! isDeficient ( i ) ) { return false ; } } else if ( ! isDeficient ( i ) || ! isDeficient ( num / i ) ) { return false ; } } } return true ; } public static void Main ( ) { int n = 20 ; if ( checkPrimitiveAbundant ( n ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Sum of the first N Pronic Numbers | C # implementation implementation to find sum of first N terms ; Function to calculate the sum ; Driver code
using System ; class GFG { static int calculateSum ( int N ) { return N * ( N - 1 ) / 2 + N * ( N - 1 ) * ( 2 * N - 1 ) / 6 ; } public static void Main ( ) { int N = 3 ; Console . Write ( calculateSum ( N ) ) ; } }
Canada Numbers | C # implementation for the above approach ; Function to calculate sum of all trivial divisors of given natural number ; Final result of summation of trivial 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 ; Function to return sum of squares of digits of N ; Function to check if N is a Canada number ; Driver Code ; Given Number ; Function Call
using System ; class GFG { static int divSum ( int num ) { int result = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return ( result - 1 - num ) ; } static int getSum ( int n ) { int sum = 0 ; while ( n != 0 ) { int r = n % 10 ; sum = sum + r * r ; n = n / 10 ; } return sum ; } static bool isCanada ( int n ) { return divSum ( n ) == getSum ( n ) ; } public static void Main ( ) { int n = 125 ; if ( isCanada ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Self Numbers | C # implementation to check if the number is a self number or not ; Function to find the sum of digits of a number N ; Function to check for Self number ; Driver code
using System ; class GFG { static int getSum ( int n ) { int sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } static bool isSelfNum ( int n ) { for ( int m = 1 ; m <= n ; m ++ ) { if ( m + getSum ( m ) == n ) return false ; } return true ; } public static void Main ( ) { int n = 20 ; if ( isSelfNum ( n ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Central binomial coefficient | C # implementation to find the Nth Central Binomial Coefficient ; Function to find the value of Nth Central Binomial Coefficient ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; Driver Code
using System ; class GFG { static int binomialCoeff ( int n , int k ) { int [ , ] C = new int [ n + 1 , k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . Min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i , j ] = 1 ; else C [ i , j ] = C [ i - 1 , j - 1 ] + C [ i - 1 , j ] ; } } return C [ n , k ] ; } public static void Main ( ) { int n = 3 ; int k = n ; n = 2 * n ; Console . Write ( binomialCoeff ( n , k ) ) ; } }
Multiply perfect number | C # implementation of the above approach ; Function to find the sum of divisors ; Note that this loop runs till square root of N ; If divisors are equal , take only one of them ; Otherwise take both ; Function to check Multiply - perfect number ; Driver code
using System ; class GFG { static int getSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) sum = sum + i ; else { sum = sum + i ; sum = sum + ( n / i ) ; } } } return sum ; } static bool MultiplyPerfectNumber ( int n ) { if ( getSum ( n ) % n == 0 ) return true ; else return false ; } public static void Main ( ) { int n = 28 ; if ( MultiplyPerfectNumber ( n ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Perfect totient number | C # implementation to find the number of digits in a Nth fibonacci number ; Function to find the Totient number of the given value ; Initialize result as n ; Consider all prime factors of n and subtract their multiples from result ; Check if p is a prime factor ; If yes , then update N and result ; If n has a prime factor greater than sqrt ( n ) ( There can be at - most one such prime factor ) ; Function to check if the number is a perfect totient number ; Store original value of n ; Loop to calculate sum of iterated totients ; Condition for Perfect Totient Number ; Driver Code
using System ; class GFG { static int phi ( int n ) { int result = n ; for ( int p = 2 ; p * p <= n ; ++ p ) { if ( n % p == 0 ) { while ( n % p == 0 ) { n /= p ; } result -= result / p ; } } if ( n > 1 ) result -= result / n ; return result ; } static bool isPerfectTotientNum ( int n ) { int temp = n ; int sum = 0 ; while ( n > 1 ) { sum = sum + phi ( n ) ; n = phi ( n ) ; } if ( sum == temp ) return true ; return false ; } public static void Main ( ) { int n = 9 ; if ( isPerfectTotientNum ( n ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Cunningham Numbers | C # implementation for the above approach ; Function to check if a number can be expressed as a ^ b . ; Function to check if N is a Cunningham number ; Driver Code ; Given number ; Function Call
using System ; class GFG { static bool isPower ( int a ) { if ( a == 1 ) return true ; for ( int i = 2 ; i * i <= a ; i ++ ) { double val = Math . Log ( a ) / Math . Log ( i ) ; if ( ( val - ( int ) val ) < 0.00000001 ) return true ; } return false ; } static bool isCunningham ( int n ) { return isPower ( n - 1 ) || isPower ( n + 1 ) ; } public static void Main ( string [ ] args ) { int n = 126 ; if ( isCunningham ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Product of all Subarrays of an Array | Set 2 | C # program for the above approach ; Function to find the product of elements of all subarray ; Initialize the result ; Computing the product of subarray using formula ; Return the product of all elements of each subarray ; Driver code ; Given array arr [ ] ; Function Call
using System ; class GFG { static int SubArrayProdct ( int [ ] arr , int n ) { int result = 1 ; for ( int i = 0 ; i < n ; i ++ ) result *= ( int ) ( Math . Pow ( arr [ i ] , ( i + 1 ) * ( n - i ) ) ) ; return result ; } public static void Main ( ) { int [ ] arr = new int [ ] { 2 , 4 } ; int N = arr . Length ; Console . Write ( SubArrayProdct ( arr , N ) ) ; } }
Number of ways to reach ( M , N ) in a matrix starting from the origin without visiting ( X , Y ) | C # program from the above approach ; Function for computing nCr ; Function to find factorial of a number ; Function for counting the number of ways to reach ( m , n ) without visiting ( x , y ) ; Driver code ; Given dimensions of Matrix ; Cell not to be visited ; Function call
using System ; class GFG { public static int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } public static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } public static int countWays ( int m , int n , int x , int y ) { return nCr ( m + n , m ) - nCr ( x + y , x ) * nCr ( m + n - x - y , m - x ) ; } public static void Main ( String [ ] args ) { int m = 5 ; int n = 4 ; int x = 3 ; int y = 2 ; Console . WriteLine ( countWays ( m , n , x , y ) ) ; } }
Smallest number greater than or equal to N using only digits 1 to K | C # program to find the smallest number greater than or equal to N which is made up of first K digits ; Function to count the digits greater than K ; Function to print the list ; Function to find the number greater than or equal to n , which is only made of first k digits ; If the number itself satisfy the conditions ; Check digit from back ; If digit > K is present previously and current digit is less than K ; If current digit is greater than K ; If an extra digit needs to be added ; Print the number ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int CountGreater ( int n , int k ) { int a = 0 ; while ( n > 0 ) { if ( ( n % 10 ) > k ) { a ++ ; } n = n / 10 ; } return a ; } static void PrintList ( List < int > ans ) { foreach ( int it in ans ) Console . Write ( it ) ; } static void getNumber ( int n , int k ) { int count = CountGreater ( n , k ) ; if ( count == 0 ) { Console . Write ( n ) ; return ; } List < int > ans = new List < int > ( ) ; bool changed = false ; while ( n > 0 ) { int digit = n % 10 ; if ( changed == true ) { ans . Insert ( 0 , digit ) ; } else { if ( count == 0 && digit < k ) { ans . Insert ( 0 , digit + 1 ) ; changed = true ; } else { ans . Insert ( 0 , 1 ) ; if ( digit > k ) { count -- ; } } } n = n / 10 ; } if ( changed == false ) { ans . Insert ( 0 , 1 ) ; } PrintList ( ans ) ; return ; } public static void Main ( String [ ] args ) { int N = 51234 ; int K = 4 ; getNumber ( N , K ) ; } }
Find the Batting Average of a batsman | C # program to calculate the average of a batsman ; Function to find the average of a batsman ; Calculate number of dismissals ; Check for 0 times out ; Calculate batting average ; Driver code
using System ; class GFG { static int averageRuns ( int runs , int matches , int notout ) { int out1 ; out1 = matches - notout ; if ( out1 == 0 ) return - 1 ; int avg = ( runs ) / out1 ; return avg ; } public static void Main ( string [ ] args ) { int runs = 10000 ; int matches = 250 ; int notout = 50 ; int avg = averageRuns ( runs , matches , notout ) ; if ( avg == - 1 ) Console . Write ( " NA " ) ; else Console . Write ( avg ) ; } }
Sum of series formed by difference between product and sum of N natural numbers | C # program to calculate the sum upto the Nth term of the given series ; Recursive Function to calculate the sum upto Nth term ; If N - th term is calculated ; Update multi to store product upto K ; Update add to store sum upto K ; Update prevSum to store sum upto K ; Proceed to next K ; Function to calculate and return the Sum upto Nth term ; Recursive Function ; Driver code
using System ; class GFG { static int seriesSumUtil ( int k , int n , int prevSum , int multi , int add ) { if ( k == n + 1 ) { return prevSum ; } multi = multi * k ; add = add + k ; prevSum = prevSum + multi - add ; return seriesSumUtil ( k + 1 , n , prevSum , multi , add ) ; } static int seriesSum ( int n ) { if ( n == 1 ) return 0 ; int prevSum = 0 ; int multi = 1 ; int add = 1 ; return seriesSumUtil ( 2 , n , prevSum , multi , add ) ; } public static void Main ( String [ ] args ) { int N = 5 ; Console . WriteLine ( seriesSum ( N ) ) ; } }
Count of total bits toggled / flipped in binary representation of 0 to N | C # program to count the number of toggles required to generate all numbers from 0 to N ; Function to count and print the required number of toggles ; Store the count of toggles ; Add the contribution of the current LSB ; Update N ; Print the result ; Driver code
using System ; class GFG { static void solve ( int N ) { int ans = 0 ; while ( N != 0 ) { ans += N ; N /= 2 ; } Console . Write ( ans ) ; } public static void Main ( string [ ] args ) { int N = 5 ; solve ( N ) ; } }
Maximum Bitwise AND pair ( X , Y ) from given range such that X and Y can be same | C # implementation to find the maximum Bitwise AND pair ( X , Y ) from given range such that X and Y can be same ; Function to return the maximum bitwise AND ; Driver code
using System ; class GFG { static int maximumAND ( int L , int R ) { return R ; } public static void Main ( String [ ] args ) { int l = 3 ; int r = 7 ; Console . Write ( maximumAND ( l , r ) ) ; } }
Check if K distinct array elements form an odd sum | C # program for the above approach ; Function to return if odd sum is possible or not ; Stores distinct odd elements ; Stores distinct even elements ; Iterating through given array ; If element is even ; If element is odd ; If atleast K elements in the array are odd ; Check for all odd frequencies of odd elements whether sufficient even numbers are present or not ; Count of even numbers required ; If required even numbers are present in the array ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool oddSum ( int [ ] A , int N , int K ) { HashSet < int > Odd = new HashSet < int > ( ) ; HashSet < int > Even = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 == 0 ) { Even . Add ( A [ i ] ) ; } else { Odd . Add ( A [ i ] ) ; } } if ( Odd . Count >= K ) return true ; bool flag = false ; for ( int i = 1 ; i < K ; i += 2 ) { int needed = K - i ; if ( needed <= Even . Count ) { return true ; } } return flag ; } public static void Main ( String [ ] args ) { int K = 5 ; int [ ] A = { 12 , 1 , 7 , 7 , 26 , 18 } ; int N = 3 ; if ( oddSum ( A , N , K ) ) Console . Write ( " YES " ) ; else Console . Write ( " NO " ) ; } }
Count of elements not divisible by any other elements of Array | C # program for the above approach ; Function to count the number of elements of array which are not divisible by any other element of same array ; Length for bool array ; Hash map for storing the element and it 's frequency ; Update the maximum element ; Boolean array of size of the max element + 1 ; Marking the multiples as false ; To store the readonly count ; Traverse bool array ; Check if i is not divisible by any other array elements and appears in the array only once ; Return the readonly Count ; Driver Code ; Given array ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int countEle ( int [ ] a , int n ) { int len = 0 ; Dictionary < int , int > hmap = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { len = Math . Max ( len , a [ i ] ) ; if ( hmap . ContainsKey ( a [ i ] ) ) { hmap [ a [ i ] ] ++ ; } else { hmap . Add ( a [ i ] , 1 ) ; } } bool [ ] v = new bool [ len + 1 ] ; for ( int i = 0 ; i <= len ; i ++ ) { v [ i ] = true ; } for ( int i = 0 ; i < n ; i ++ ) { if ( v [ a [ i ] ] == false ) continue ; for ( int j = 2 * a [ i ] ; j <= len ; j += a [ i ] ) { v [ j ] = false ; } } int count = 0 ; for ( int i = 1 ; i <= len ; i ++ ) { if ( v [ i ] == true && hmap . ContainsKey ( i ) && hmap [ i ] == 1 && hmap [ i ] == 1 ) { count += 1 ; } } return count ; } public static void Main ( String [ ] args ) { int [ ] arr = { 86 , 45 , 18 , 4 , 8 , 28 , 19 , 33 , 2 } ; int n = arr . Length ; Console . Write ( countEle ( arr , n ) ) ; } }
Smallest N digit number divisible by N | C # program for the above approach ; Function to find the smallest N - digit number divisible by N ; Find largest n digit number ; Find smallest n digit number ; If i is divisible by N , then print i and return ; ; Driver Code ; Given number ; Function call
using System ; class GFG { static void smallestNumber ( int N ) { int L = ( int ) ( Math . Pow ( 10 , N ) - 1 ) ; int S = ( int ) Math . Pow ( 10 , N - 1 ) ; for ( int i = S ; i <= L ; i ++ ) { if ( i % N == 0 ) { Console . Write ( i ) ; return ; } } } public static void Main ( ) { int N = 2 ; smallestNumber ( N ) ; } }
Number less than equals to N with maximum product of prime factors | C # program for the above approach ; Function to find the smallest number having a maximum product of prime factors ; Declare the array [ ] arr ; Initialise array with 1 ; Iterate from [ 2 , N ] ; If value at index i is 1 , then i is prime and make update array at index for all multiples of i ; Initialise maxValue ; Find number having maximum product of prime factor <= N ; Find the maximum value ; Driver Code ; Given number ; Function call
using System ; class GFG { static int maxPrimefactorNum ( int N ) { int [ ] arr = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) arr [ i ] = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { if ( arr [ i ] == 1 ) { for ( int j = i ; j <= N ; j += i ) { arr [ j ] *= i ; } } } int maxValue = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { if ( arr [ i ] > maxValue ) { maxValue = i ; } } return maxValue ; } public static void Main ( String [ ] args ) { int N = 20 ; Console . Write ( maxPrimefactorNum ( N ) ) ; } }
Count of elements to be multiplied with integers to make each pair of Array a perfect square | C # program for the above approach ; Function to find the smallest prime factor of the elements ; Initializing the first element of the array ; Loop to add the remaining elements to the array ; Marking the smallest prime factor for every number to be itself ; Separately marking spf for every even number as 2 ; Checking if i is prime ; Marking SPF for all the numbers divisible by i ; Marking spf [ j ] if it is not previously marked ; Function to find the minimum number of steps to modify the array such that the product of any two numbers in the array is a perfect square ; Map created to store the unique prime numbers ; Variable to store the minimum number of operations ; Loop to store every unique prime number ; Erasing 1 as a key because it is not a prime number ; Iterating through the hash ; Two variables used for counting the frequency of prime is even or odd ; First prime number ; Iterating the number D ; Check if prime is a factor of the element in the array ; Loop for calculating the frequency of the element ; Check for frequency odd or even ; If it is not a factor of the element , then it is automatically even ; Storing the minimum of two variable even or odd ; Driver Code ; Input array ; Creating shortest prime factorisation array
using System ; using System . Collections . Generic ; class GFG { static void spf_array ( int [ ] spf ) { spf [ 1 ] = 1 ; for ( int i = 2 ; i < 1000 ; i ++ ) spf [ i ] = i ; for ( int i = 4 ; i < 1000 ; i += 2 ) spf [ i ] = 2 ; for ( int i = 3 ; i * i < 1000 ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < 1000 ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } } } static int minimum_operation ( int [ ] b , int d , int [ ] spf ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; int i = 0 ; int c = 0 ; for ( i = 0 ; i < d ; i ++ ) { int x = b [ i ] ; while ( x != 1 ) { x = x / spf [ x ] ; if ( ! m . ContainsKey ( spf [ x ] ) ) { m . Add ( spf [ x ] , 1 ) ; } } } m . Remove ( 1 ) ; foreach ( KeyValuePair < int , int > x in m ) { int e = 0 , o = 0 ; int j = x . Key ; for ( i = 0 ; i < d ; i ++ ) { if ( b [ i ] % j == 0 ) { int h = 0 ; int g = b [ i ] ; while ( g != 0 ) { if ( g % j != 0 ) { break ; } g = g / j ; h = h + 1 ; } if ( h % 2 == 0 ) { e = e + 1 ; } else { o = o + 1 ; } } else { e = e + 1 ; } } c = c + Math . Min ( o , e ) ; } return c ; } public static void Main ( String [ ] args ) { int [ ] spf = new int [ 1001 ] ; int [ ] b = { 1 , 4 , 6 } ; int d = b . Length ; spf_array ( spf ) ; Console . Write ( minimum_operation ( b , d , spf ) ) ; } }