codeparrot/xlcost-text-to-code huggingface dataset:
Minimum time to return array to its original state after given modifications | C # implementation of above approach ; Function to return lcm of two numbers ; Make a graph ; Add edge ; Count reachable nodes from every node . ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int lcm ( int a , int b ) { return ( a * b ) / ( __gcd ( a , b ) ) ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static int dfs ( int src , List < int > [ ] adj , bool [ ] visited ) { visited [ src ] = true ; int count = 1 ; for ( int i = 0 ; i < adj [ src ] . Count ; i ++ ) if ( ! visited [ adj [ src ] [ i ] ] ) count += dfs ( adj [ src ] [ i ] , adj , visited ) ; return count ; } static int findMinTime ( int [ ] arr , int [ ] P , int n ) { List < int > [ ] adj = new List < int > [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) adj [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { adj [ arr [ i ] ] . Add ( P [ i ] ) ; } bool [ ] visited = new bool [ n + 1 ] ; int ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! visited [ i ] ) { ans = lcm ( ans , dfs ( i , adj , visited ) ) ; } } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 } ; int [ ] P = { 3 , 2 , 1 } ; int n = arr . Length ; Console . Write ( findMinTime ( arr , P , n ) ) ; } }
Check whether product of digits at even places of a number is divisible by K | C # implementation of the above approach ; below function checks whether product of digits at even places is divisible by K ; if position is even ; Driver code
using System ; class GFG { static bool productDivisible ( int n , int k ) { int product = 1 , position = 1 ; while ( n > 0 ) { if ( position % 2 == 0 ) product *= n % 10 ; n = n / 10 ; position ++ ; } if ( product % k == 0 ) return true ; return false ; } public static void Main ( ) { int n = 321922 ; int k = 3 ; if ( productDivisible ( n , k ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Permutations of n things taken r at a time with k things together | C # program to find the number of permutations of n different things taken r at a time with k things grouped together ; Function to find factorial of a number ; Function to calculate p ( n , r ) ; Function to find the number of permutations of n different things taken r at a time with k things grouped together ; Driver code
using System ; class GFG { static int factorial ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } static int npr ( int n , int r ) { int pnr = factorial ( n ) / factorial ( n - r ) ; return pnr ; } static int countPermutations ( int n , int r , int k ) { return factorial ( k ) * ( r - k + 1 ) * npr ( n - k , r - k ) ; } static void Main ( ) { int n = 8 ; int r = 5 ; int k = 2 ; Console . WriteLine ( countPermutations ( n , r , k ) ) ; } }
Greatest Integer Function | C # program to illustrate greatest integer Function ; Function to calculate the GIF value of a number ; GIF is the floor of a number ; Driver code
using System ; class GFG { static int GIF ( double n ) { return ( int ) Math . Floor ( n ) ; } static void Main ( ) { double n = 2.3 ; Console . WriteLine ( GIF ( n ) ) ; } }
Number of triangles formed from a set of points on three lines | C # program to find the possible number of triangles that can be formed from set of points on three lines ; Returns factorial of a number ; calculate c ( n , r ) ; Driver code
using System ; class GFG { static int factorial ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } static int ncr ( int n , int r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } public static void Main ( ) { int m = 3 , n = 4 , k = 5 ; int totalTriangles = ncr ( m + n + k , 3 ) - ncr ( m , 3 ) - ncr ( n , 3 ) - ncr ( k , 3 ) ; Console . WriteLine ( totalTriangles ) ; } }
Check whether sum of digits at odd places of a number is divisible by K | C # implementation of the approach ; function that checks the divisibility of the sum of the digits at odd places of the given number ; if position is odd ; Driver code
using System ; class GFG { static bool SumDivisible ( int n , int k ) { int sum = 0 , position = 1 ; while ( n > 0 ) { if ( position % 2 == 1 ) sum += n % 10 ; n = n / 10 ; position ++ ; } if ( sum % k == 0 ) return true ; return false ; } static public void Main ( ) { int n = 592452 ; int k = 3 ; if ( SumDivisible ( n , k ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Check whether sum of digits at odd places of a number is divisible by K | C # implementation of the above approach ; Converting integer to string ; Traversing the string ; Driver code
using System ; class GFG { static bool sumDivisible ( int n , int k ) { int sum = 0 ; string num = n . ToString ( ) ; int i ; for ( i = 0 ; i < num . Length ; i ++ ) { if ( i % 2 != 0 ) { sum = sum + ( num [ i ] - '0' ) ; } } if ( sum % k == 0 ) { return true ; } else { return false ; } } static public void Main ( ) { int n = 592452 ; int k = 3 ; if ( sumDivisible ( n , k ) ) { Console . Write ( " YES " ) ; } else { Console . Write ( " NO " ) ; } } }
Check if a triangle of positive area is possible with the given angles | C # program to check if a triangle of positive area is possible with the given angles ; Checking if the sum of three angles is 180 and none of the angles is zero ; Checking if sum of any two angles is greater than equal to the third one ; Driver Code
class GFG { static string isTriangleExists ( int a , int b , int c ) { if ( a != 0 && b != 0 && c != 0 && ( a + b + c ) == 180 ) if ( ( a + b ) >= c || ( b + c ) >= a || ( a + c ) >= b ) return " YES " ; else return " NO " ; else return " NO " ; } static void Main ( ) { int a = 50 , b = 60 , c = 70 ; System . Console . WriteLine ( isTriangleExists ( a , b , c ) ) ; } }
Find maximum value of x such that n ! % ( k ^ x ) = 0 | C # program to maximize the value of x such that n ! % ( k ^ x ) = 0 ; Function to maximize the value of x such that n ! % ( k ^ x ) = 0 ; Find square root of k and add 1 to it ; Run the loop from 2 to m and k should be greater than 1 ; optimize the value of k ; Minimum store ; Driver Code
using System ; class GfG { public int findX ( int n , int k ) { int r = n , v , u ; int m = ( int ) Math . Sqrt ( k ) + 1 ; for ( int i = 2 ; i <= m && k > 1 ; i ++ ) { if ( i == m ) { i = k ; } for ( u = v = 0 ; k % i == 0 ; v ++ ) { k /= i ; } if ( v > 0 ) { int t = n ; while ( t > 0 ) { t /= i ; u += t ; } r = Math . Min ( r , u / v ) ; } } return r ; } } class geek { public static void Main ( ) { GfG g = new GfG ( ) ; int n = 5 ; int k = 2 ; Console . WriteLine ( g . findX ( n , k ) ) ; } }
Ways of selecting men and women from a group to make a team | C # implementation of the approach ; Returns factorial of the number ; Function to calculate ncr ; Function to calculate the total possible ways ; Driver code
class GFG { static int fact ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) fact *= i ; return fact ; } static int ncr ( int n , int r ) { int ncr = fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; return ncr ; } static int ways ( int m , int w , int n , int k ) { int ans = 0 ; while ( m >= k ) { ans += ncr ( m , k ) * ncr ( w , n - k ) ; k += 1 ; } return ans ; } static void Main ( ) { int m , w , n , k ; m = 7 ; w = 6 ; n = 5 ; k = 3 ; System . Console . WriteLine ( ways ( m , w , n , k ) ) ; } }
Product of every K ’ th prime number in an array | C # implementation of the approach ; 0 and 1 are not prime numbers ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; compute the answer ; count of primes ; product of the primes ; traverse the array ; if the number is a prime ; increase the count ; if it is the K 'th prime ; Driver code ; create the sieve
class GFG { static int MAX = 1000000 ; static bool [ ] prime = new bool [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { prime [ 1 ] = true ; prime [ 0 ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == false ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = true ; } } } static void productOfKthPrimes ( int [ ] arr , int n , int k ) { int c = 0 ; int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! prime [ arr [ i ] ] ) { c ++ ; if ( c % k == 0 ) { product *= arr [ i ] ; c = 0 ; } } } System . Console . WriteLine ( product ) ; } static void Main ( ) { SieveOfEratosthenes ( ) ; int n = 5 , k = 2 ; int [ ] arr = new int [ ] { 2 , 3 , 5 , 7 , 11 } ; productOfKthPrimes ( arr , n , k ) ; } }
Sum of greatest odd divisor of numbers in given range | C # program to find sum of greatest odd divisor of numbers in given range ; Function to return sum of first n odd numbers ; Recursive function to return sum of greatest odd divisor of numbers in range [ 1 , n ] ; Odd n ; Even n ; Function to return sum of greatest odd divisor of numbers in range [ a , b ] ; Driver code
using System ; class gfg { public int square ( int n ) { return n * n ; } public int sum ( int n ) { if ( n == 0 ) return 0 ; if ( n % 2 == 1 ) { return square ( ( n + 1 ) / 2 ) + sum ( n / 2 ) ; } else { return square ( n / 2 ) + sum ( n / 2 ) ; } } public int oddDivSum ( int a , int b ) { return sum ( b ) - sum ( a - 1 ) ; } } class geek { public static int Main ( ) { gfg g = new gfg ( ) ; int a = 3 , b = 9 ; Console . WriteLine ( g . oddDivSum ( a , b ) ) ; return 0 ; } }
Minimum numbers needed to express every integer below N as a sum | C # program to find count of integers needed to express all numbers from 1 to N ; function to count length of binary expression of n ; Driver code
using System ; class GFG { static int countBits ( int n ) { int count = 0 ; while ( n > 0 ) { count ++ ; n >>= 1 ; } return count ; } static public void Main ( ) { int n = 32 ; Console . WriteLine ( " Minimum ▁ value ▁ of ▁ K ▁ is ▁ = ▁ " + countBits ( n ) ) ; } }
Check if a number is an Achilles number or not | Program to check if the given number is an Achilles Number ; function to check if the number is powerful number ; First divide the number repeatedly by 2 ; If only 2 ^ 1 divides n ( not higher powers ) , then return false ; if n is not a power of 2 then this loop will execute repeat above process ; Find highest power of " factor " that divides n ; If only factor ^ 1 divides n ( not higher powers ) , then return false ; n must be 1 now if it is not a prime number . Since prime numbers are not powerful , we return false if n is not 1. ; Utility function to check if number is a perfect power or not ; Function to check Achilles Number ; Driver Program
using System ; class GFG { static bool isPowerful ( int n ) { while ( n % 2 == 0 ) { int power = 0 ; while ( n % 2 == 0 ) { n /= 2 ; power ++ ; } if ( power == 1 ) return false ; } for ( int factor = 3 ; factor <= Math . Sqrt ( n ) ; factor += 2 ) { int power = 0 ; while ( n % factor == 0 ) { n = n / factor ; power ++ ; } if ( power == 1 ) return false ; } return ( n == 1 ) ; } 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 isAchillesNumber ( int n ) { if ( isPowerful ( n ) && ! isPower ( n ) ) return true ; else return false ; } public static void Main ( ) { int n = 72 ; if ( isAchillesNumber ( n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; n = 36 ; if ( isAchillesNumber ( n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Program to find count of numbers having odd number of divisors in given range | C # program to find count of numbers having odd number of divisors in given range ; Function to count numbers having odd number of divisors in range [ A , B ] ; variable to odd divisor count ; iterate from a to b and count their number of divisors ; variable to divisor count ; if count of divisor is odd then increase res by 1 ; Driver code
using System ; class Geeks { static int OddDivCount ( int a , int b ) { int res = 0 ; for ( int i = a ; i <= b ; ++ i ) { int divCount = 0 ; for ( int j = 1 ; j <= i ; ++ j ) { if ( i % j == 0 ) { ++ divCount ; } } if ( ( divCount % 2 ) != 0 ) { ++ res ; } } return res ; } public static void Main ( String [ ] args ) { int a = 1 , b = 10 ; Console . WriteLine ( OddDivCount ( a , b ) ) ; } }
Largest factor of a given number which is a perfect square | C # program to find the largest factor of a number which is also a perfect square ; Function to find the largest factor of a given number which is a perfect square ; Initialise the answer to 1 ; Finding the prime factors till sqrt ( num ) ; Frequency of the prime factor in the factorisation initialised to 0 ; If the frequency is odd then multiply i frequency - 1 times to the answer ; Else if it is even , multiply it frequency times ; Driver Code
using System ; class GFG { static double largestSquareFactor ( double num ) { double answer = 1 ; for ( int i = 2 ; i < Math . Sqrt ( num ) ; ++ i ) { int cnt = 0 ; int j = i ; while ( num % j == 0 ) { cnt ++ ; j *= i ; } if ( ( cnt & 1 ) != 0 ) { cnt -- ; answer *= Math . Pow ( i , cnt ) ; } else { answer *= Math . Pow ( i , cnt ) ; } } return answer ; } static public void Main ( ) { int N = 420 ; Console . WriteLine ( largestSquareFactor ( N ) ) ; } }
Find the Nth term of the series 2 + 6 + 13 + 23 + . . . | C # program to find Nth term of the series 2 + 6 + 13 + 23 + 36 + ... ; calculate Nth term of given series ; Driver code
class GFG { static int Nth_Term ( int n ) { return ( int ) ( 3 * System . Math . Pow ( n , 2 ) - n + 2 ) / ( 2 ) ; } static void Main ( ) { int N = 5 ; System . Console . WriteLine ( Nth_Term ( N ) ) ; } }
All possible numbers of N digits and base B without leading zeros | C # implementation of the approach ; function to count all permutations ; count of all permutations ; count of permutations with leading zeros ; Return the permutations without leading zeros ; Driver code
using System ; class GFG { static void countPermutations ( int N , int B ) { int x = ( int ) Math . Pow ( B , N ) ; int y = ( int ) Math . Pow ( B , N - 1 ) ; Console . WriteLine ( x - y ) ; } public static void Main ( ) { int N = 6 ; int B = 4 ; countPermutations ( N , B ) ; } }
Absolute difference between the Product of Non | C # program to find the Absolute Difference between the Product of Non - Prime numbers and Prime numbers of an Array ; Function to find the difference between the product of non - primes and the product of primes of an array . ; Find maximum value in the array ; USE SIEVE TO FIND ALL PRIME NUMBERS LESS THAN OR EQUAL TO max_val Create a boolean array " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Remaining part of SIEVE ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Store the product of primes in P1 and the product of non primes in P2 ; the number is prime ; the number is non - prime ; Return the absolute difference ; Driver Code ; Find the absolute difference
using System ; using System . Linq ; class GFG { static int calculateDifference ( int [ ] arr , int n ) { int max_val = arr . Max ( ) ; var prime = Enumerable . Repeat ( true , max_val + 1 ) . ToArray ( ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int P1 = 1 , P2 = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { P1 *= arr [ i ] ; } else if ( arr [ i ] != 1 ) { P2 *= arr [ i ] ; } } return Math . Abs ( P2 - P1 ) ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 3 , 5 , 10 , 15 , 7 } ; int n = arr . Length ; Console . WriteLine ( calculateDifference ( arr , n ) ) ; } }
Maximum count of equal numbers in an array after performing given operations | C # program to find the maximum number of equal numbers in an array ; Function to find the maximum number of equal numbers in an array ; to store sum of elements ; if sum of numbers is not divisible by n ; Driver code ; size of an array
using System ; class GFG { static int EqualNumbers ( int [ ] a , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; if ( sum % n != 0 ) return n - 1 ; return n ; } static public void Main ( ) { int [ ] a = { 1 , 4 , 1 } ; int n = a . Length ; Console . WriteLine ( EqualNumbers ( a , n ) ) ; } }
Count number of ordered pairs with Even and Odd Sums | C # implementation of the above approach ; function to count odd sum pair ; if number is even ; if number is odd ; count of ordered pairs ; function to count even sum pair ; Driver code
using System ; class GFG { static int count_odd_pair ( int n , int [ ] a ) { int odd = 0 , even = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } int ans = odd * even * 2 ; return ans ; } static int count_even_pair ( int odd_sum_pairs , int n ) { int total_pairs = ( n * ( n - 1 ) ) ; int ans = total_pairs - odd_sum_pairs ; return ans ; } public static void Main ( ) { int n = 6 ; int [ ] a = { 2 , 4 , 5 , 9 , 1 , 8 } ; int odd_sum_pairs = count_odd_pair ( n , a ) ; int even_sum_pairs = count_even_pair ( odd_sum_pairs , n ) ; Console . WriteLine ( " Even ▁ Sum ▁ Pairs ▁ = ▁ " + even_sum_pairs ) ; Console . WriteLine ( " Odd ▁ Sum ▁ Pairs = ▁ " + odd_sum_pairs ) ; } }
Steps required to visit M points in order on a circular ring of N points | C # implementation of the approach ; Function to count the steps required ; Start at 1 ; Initialize steps ; If nxt is greater than cur ; Now we are at a [ i ] ; Driver code
using System ; class GFG { static int findSteps ( int n , int m , int [ ] a ) { int cur = 1 ; int steps = 0 ; for ( int i = 0 ; i < m ; i ++ ) { if ( a [ i ] >= cur ) steps += ( a [ i ] - cur ) ; else steps += ( n - cur + a [ i ] ) ; cur = a [ i ] ; } return steps ; } public static void Main ( ) { int n = 3 , m = 3 ; int [ ] a = { 2 , 1 , 2 } ; Console . WriteLine ( findSteps ( n , m , a ) ) ; } }
Program to Convert Hexadecimal Number to Binary | C # program to convert Hexadecimal number to Binary ; function to convert Hexadecimal to Binary Number ; Driver code ; Get the Hexadecimal number ; Convert HexaDecimal to Binary
class GFG { static void HexToBin ( char [ ] hexdec ) { int i = 0 ; while ( hexdec [ i ] != ' \u0000' ) { switch ( hexdec [ i ] ) { case '0' : System . Console . Write ( "0000" ) ; break ; case '1' : System . Console . Write ( "0001" ) ; break ; case '2' : System . Console . Write ( "0010" ) ; break ; case '3' : System . Console . Write ( "0011" ) ; break ; case '4' : System . Console . Write ( "0100" ) ; break ; case '5' : System . Console . Write ( "0101" ) ; break ; case '6' : System . Console . Write ( "0110" ) ; break ; case '7' : System . Console . Write ( "0111" ) ; break ; case '8' : System . Console . Write ( "1000" ) ; break ; case '9' : System . Console . Write ( "1001" ) ; break ; case ' A ' : case ' a ' : System . Console . Write ( "1010" ) ; break ; case ' B ' : case ' b ' : System . Console . Write ( "1011" ) ; break ; case ' C ' : case ' c ' : System . Console . Write ( "1100" ) ; break ; case ' D ' : case ' d ' : System . Console . Write ( "1101" ) ; break ; case ' E ' : case ' e ' : System . Console . Write ( "1110" ) ; break ; case ' F ' : case ' f ' : System . Console . Write ( "1111" ) ; break ; default : System . Console . Write ( " STRNEWLINE Invalid ▁ hexadecimal ▁ digit ▁ " + hexdec [ i ] ) ; break ; } i ++ ; } } static void Main ( ) { string s = "1AC5" ; char [ ] hexdec = new char [ 100 ] ; hexdec = s . ToCharArray ( ) ; System . Console . Write ( " Equivalent ▁ Binary ▁ value ▁ is ▁ : ▁ " ) ; try { HexToBin ( hexdec ) ; } catch ( System . IndexOutOfRangeException ) { System . Console . Write ( " " ) ; } } }
Count unordered pairs ( i , j ) such that product of a [ i ] and a [ j ] is power of two | C # program to Count unordered pairs ( i , j ) in array such that product of a [ i ] and a [ j ] can be expressed as power of two ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Function to Count unordered pairs ; is a number can be expressed as power of two ; count total number of unordered pairs ; Driver code
using System ; public class GFG { static bool isPowerOfTwo ( int x ) { return ( x > 0 && ( ! ( ( x & ( x - 1 ) ) > 0 ) ) ) ; } static void Count_pairs ( int [ ] a , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPowerOfTwo ( a [ i ] ) ) count ++ ; } int ans = ( count * ( count - 1 ) ) / 2 ; Console . WriteLine ( ans ) ; } static public void Main ( ) { int [ ] a = { 2 , 5 , 8 , 16 , 128 } ; int n = a . Length ; Count_pairs ( a , n ) ; } }
Ways of dividing a group into two halves such that two elements are in different groups | C # Program to count Number of ways in which two Beautiful girls are in different groupusing System ; ; This function will return the factorial of a given number ; This function will calculate nCr of given n and r ; This function will Calculate number of ways ; Driver Code
using System ; public class GFG { static int factorial ( int n ) { int result = 1 ; for ( int i = 1 ; i <= n ; i ++ ) result = result * i ; return result ; } static int nCr ( int n , int r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } static int calculate_result ( int n ) { int result = 2 * nCr ( ( n - 2 ) , ( n / 2 - 1 ) ) ; return result ; } public static void Main ( ) { int a = 2 , b = 4 ; Console . WriteLine ( calculate_result ( 2 * a ) ) ; Console . Write ( calculate_result ( 2 * b ) ) ; } }
Print values of ' a ' in equation ( a + b ) <= n and a + b is divisible by x | C # program to Find values of a , in equation ( a + b ) <= n and a + b is divisible by x . ; function to Find values of a , in equation ( a + b ) <= n and a + b is divisible by x . ; least possible which is divisible by x ; run a loop to get required answer ; increase value by x ; answer is possible ; Driver code ; function call
using System ; class GFG { static void PossibleValues ( int b , int x , int n ) { int leastdivisible = ( b / x + 1 ) * x ; int flag = 1 ; while ( leastdivisible <= n ) { if ( leastdivisible - b >= 1 ) { Console . Write ( leastdivisible - b + " ▁ " ) ; leastdivisible += x ; flag = 0 ; } else break ; } if ( flag > 0 ) Console . WriteLine ( - 1 ) ; } public static void Main ( ) { int b = 10 , x = 6 , n = 40 ; PossibleValues ( b , x , n ) ; } }
Check if all sub | C # program to check if all sub - numbers have distinct Digit product ; Function to calculate product of digits between given indexes ; Function to check if all sub - numbers have distinct Digit product ; Length of number N ; Digit array ; List to maintain digit products ; Finding all possible subarrays ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; public class GFG { static int digitProduct ( int [ ] digits , int start , int end ) { int pro = 1 ; for ( int i = start ; i <= end ; i ++ ) { pro *= digits [ i ] ; } return pro ; } static bool isDistinct ( int N ) { string s = N . ToString ( ) ; int len = s . Length ; int [ ] digits = new int [ len ] ; ArrayList products = new ArrayList ( ) ; for ( int i = 0 ; i < len ; i ++ ) { digits [ i ] = s [ i ] - '0' ; } for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i ; j < len ; j ++ ) { int val = digitProduct ( digits , i , j ) ; if ( products . Contains ( val ) ) return false ; else products . Add ( val ) ; } } return true ; } public static void Main ( ) { int N = 324 ; if ( isDistinct ( N ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }