codeparrot/xlcost-text-to-code huggingface dataset:
Count the number of intervals in which a given value lies | C # program to count the number of intervals in which a given value lies ; Function to count the number of intervals in which a given value lies ; Variables to store overall minimum and maximum of the intervals ; Variables to store start and end of an interval ; Frequency array to keep track of how many of the given intervals an element lies in ; Constructing the frequency array ; Driver code ; length of the array
using System ; class GFG { static int MAX_VAL = 200000 ; static int countIntervals ( int [ , ] arr , int V , int N ) { int min = int . MaxValue , max = int . MinValue ; int li , ri ; int [ ] freq = new int [ MAX_VAL ] ; for ( int i = 0 ; i < N ; i ++ ) { li = arr [ i , 0 ] ; freq [ li ] = freq [ li ] + 1 ; ri = arr [ i , 1 ] ; freq [ ri + 1 ] = freq [ ri + 1 ] - 1 ; if ( li < min ) min = li ; if ( ri > max ) max = ri ; } for ( int i = min ; i <= max ; i ++ ) freq [ i ] = freq [ i ] + freq [ i - 1 ] ; return freq [ V ] ; } public static void Main ( ) { int [ , ] arr = new int [ , ] { { 1 , 10 } , { 5 , 10 } , { 15 , 25 } , { 7 , 12 } , { 20 , 25 } } ; int V = 7 ; int N = arr . Length / arr . Rank ; Console . WriteLine ( countIntervals ( arr , V , N ) ) ; } }
Split N ^ 2 numbers into N groups of equal sum | Java implementation of the above approach ; Function to print N groups of equal sum ; No . of Groups ; n / 2 pairs ; Driver code
using System ; class GFG { static void printGroups ( int n ) { int x = 1 ; int y = n * n ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n / 2 ; j ++ ) { Console . Write ( " { ▁ " + x + " , ▁ " + y + " } ▁ " ) ; x ++ ; y -- ; } Console . WriteLine ( ) ; } } public static void Main ( ) { int n = 4 ; printGroups ( n ) ; } }
Program to find the Break Even Point | C # program to find Break Even Point ; Function to calculate Break Even Point ; Calculating number of articles to be sold ; Driver Code
using System ; class GFG { public static int breakEvenPoint ( int exp1 , int S , int M ) { double earn = S - M ; double exp = exp1 ; double res = Math . Ceiling ( exp / earn ) ; int res1 = ( int ) res ; return res1 ; } public static void Main ( ) { int exp = 3550 , S = 90 , M = 65 ; Console . WriteLine ( breakEvenPoint ( exp , S , M ) ) ; } }
Minimize the value of N by applying the given operations | C # implementation of the above approach ; function to return the product of distinct prime factors of a number ; find distinct prime ; Driver code
class GFG { static int minimum ( int n ) { int product = 1 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { while ( n % i == 0 ) n = n / i ; product = product * i ; } } if ( n >= 2 ) product = product * n ; return product ; } static void Main ( ) { int n = 20 ; System . Console . WriteLine ( minimum ( n ) ) ; } }
N digit numbers divisible by 5 formed from the M digits | C # program to find the count of all possible N digit numbers which are divisible by 5 formed from M digits ; Function to find the count of all possible N digit numbers which are divisible by 5 formed from M digits ; If it is not possible to form n digit number from the given m digits without repetition ; If both zero and five exists ; Remaining N - 1 iterations ; Remaining N - 1 iterations ; Driver code
using System ; public class GFG { static int numbers ( int n , int [ ] arr , int m ) { int isZero = 0 , isFive = 0 ; int result = 0 ; if ( m < n ) { return - 1 ; } for ( int i = 0 ; i < m ; i ++ ) { if ( arr [ i ] == 0 ) { isZero = 1 ; } if ( arr [ i ] == 5 ) { isFive = 1 ; } } if ( isZero == 1 && isFive == 1 ) { result = 2 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { result = result * ( -- m ) ; } } else if ( isZero == 1 isFive == 1 ) { result = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { result = result * ( -- m ) ; } } else { result = - 1 ; } return result ; } public static void Main ( ) { int n = 3 , m = 6 ; int [ ] arr = { 2 , 3 , 5 , 6 , 7 , 9 } ; Console . WriteLine ( numbers ( n , arr , m ) ) ; } }
Program to find the smallest element among three elements | C # implementation to find the smallest of three elements
using System ; class GFG { static public void Main ( ) { int a = 5 , b = 7 , c = 10 ; if ( a <= b && a <= c ) Console . WriteLine ( a + " ▁ is ▁ the ▁ smallest " ) ; else if ( b <= a && b <= c ) Console . WriteLine ( b + " ▁ is ▁ the ▁ smallest " ) ; else Console . WriteLine ( c + " ▁ is ▁ the ▁ smallest " ) ; } }
Find subsequences with maximum Bitwise AND and Bitwise OR | C # implementation of the above approach ; Function to find the maximum sum ; Maximum AND is maximum element ; Maximum OR is bitwise OR of all . ; Driver code
using System ; using System . Linq ; public class GFG { static void maxSum ( int [ ] a , int n ) { int maxAnd = a . Max ( ) ; int maxOR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { maxOR |= a [ i ] ; } Console . Write ( ( maxAnd + maxOR ) ) ; } public static void Main ( ) { int n = 4 ; int [ ] a = { 3 , 5 , 6 , 1 } ; maxSum ( a , n ) ; } }
Sum of minimum elements of all subarrays | C # implementation of above approach ;  ; Function to return required minimum sum ; getting number of element strictly larger than A [ i ] on Left . ; get elements from stack until element greater than A [ i ] found ; getting number of element larger than A [ i ] on Right . ; get elements from stack until element greater or equal to A [ i ] found ; calculating required resultult ; Driver Code ; function call to get required result
using System ; using System . Collections . Generic ; class GFG { public class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int sumSubarrayMins ( int [ ] A , int n ) { int [ ] left = new int [ n ] ; int [ ] right = new int [ n ] ; Stack < pair > s1 = new Stack < pair > ( ) ; Stack < pair > s2 = new Stack < pair > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { int cnt = 1 ; while ( s1 . Count != 0 && ( s1 . Peek ( ) . first ) > A [ i ] ) { cnt += s1 . Peek ( ) . second ; s1 . Pop ( ) ; } s1 . Push ( new pair ( A [ i ] , cnt ) ) ; left [ i ] = cnt ; } for ( int i = n - 1 ; i >= 0 ; -- i ) { int cnt = 1 ; while ( s2 . Count != 0 && ( s2 . Peek ( ) . first ) >= A [ i ] ) { cnt += s2 . Peek ( ) . second ; s2 . Pop ( ) ; } s2 . Push ( new pair ( A [ i ] , cnt ) ) ; right [ i ] = cnt ; } int result = 0 ; for ( int i = 0 ; i < n ; ++ i ) result = ( result + A [ i ] * left [ i ] * right [ i ] ) ; return result ; } public static void Main ( String [ ] args ) { int [ ] A = { 3 , 1 , 2 , 4 } ; int n = A . Length ; Console . WriteLine ( sumSubarrayMins ( A , n ) ) ; } }
Minimum and Maximum element of an array which is divisible by a given number k | C # implementation of the above approach ; Function to find the minimum element ; Function to find the maximum element ; Driver code
using System ; class GFG { static int getMin ( int [ ] arr , int n , int k ) { int res = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { res = Math . Min ( res , arr [ i ] ) ; } } return res ; } static int getMax ( int [ ] arr , int n , int k ) { int res = int . MinValue ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { res = Math . Max ( res , arr [ i ] ) ; } } return res ; } static public void Main ( ) { int [ ] arr = { 10 , 1230 , 45 , 67 , 1 } ; int k = 10 ; int n = arr . Length ; Console . WriteLine ( " Minimum ▁ element ▁ of ▁ array ▁ " + " which ▁ is ▁ divisible ▁ by ▁ k : ▁ " + getMin ( arr , n , k ) ) ; Console . WriteLine ( " Maximum ▁ element ▁ of ▁ array ▁ " + " which ▁ is ▁ divisible ▁ by ▁ k : ▁ " + getMax ( arr , n , k ) ) ; } }
Print a number containing K digits with digital root D | C # implementation of the above approach ; Function to find a number ; If d is 0 k has to be 1 ; Print k - 1 zeroes ; Driver code
using System ; class GFG { static void printNumberWithDR ( int k , int d ) { if ( d == 0 && k != 1 ) Console . Write ( " - 1" ) ; else { Console . Write ( d ) ; k -- ; while ( k -- > 0 ) Console . Write ( "0" ) ; } } static public void Main ( ) { int k = 4 , d = 4 ; printNumberWithDR ( k , d ) ; } }
Count number of integers less than or equal to N which has exactly 9 divisors | C # implementation of above approach ; Function to count numbers having exactly 9 divisors ; Sieve array ; initially prime [ i ] = i ; use sieve concept to store the first prime factor of every number ; mark all factors of i ; check for all numbers if they can be expressed in form p * q ; p prime factor ; q prime factor ; if both prime factors are different if p * q <= n and q != ; Check if it can be expressed as p ^ 8 ; Driver Code
using System ; public class GFG { static int countNumbers ( int n ) { int c = 0 ; int limit = ( int ) Math . Sqrt ( n ) ; int [ ] prime = new int [ limit + 1 ] ; for ( int i = 1 ; i <= limit ; i ++ ) { prime [ i ] = i ; } for ( int i = 2 ; i * i <= limit ; i ++ ) { if ( prime [ i ] == i ) { for ( int j = i * i ; j <= limit ; j += i ) { if ( prime [ j ] == j ) { prime [ j ] = i ; } } } } for ( int i = 2 ; i <= limit ; i ++ ) { int p = prime [ i ] ; int q = prime [ i / prime [ i ] ] ; if ( p * q == i && q != 1 && p != q ) { c += 1 ; } else if ( prime [ i ] == i ) { if ( Math . Pow ( i , 8 ) <= n ) { c += 1 ; } } } return c ; } public static void Main ( ) { int n = 1000 ; Console . WriteLine ( countNumbers ( n ) ) ; } }
Interprime | C # program to check if a number is interprime or not ; Function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to check if the given number is interprime or not ; Smallest Interprime is 4 So the number less than 4 can not be a Interprime ; Calculate first prime number < n ; Calculate first prime number > n ; check if next_prime and prev_prime have the same average ; Driver Code
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } static bool isInterprime ( int n ) { if ( n < 4 ) return false ; int prev_prime = n ; int next_prime = n ; while ( ! isPrime ( prev_prime ) ) { prev_prime -- ; } while ( ! isPrime ( next_prime ) ) { next_prime ++ ; } if ( ( prev_prime + next_prime ) == 2 * n ) return true ; else return false ; } public static void Main ( ) { int n = 9 ; if ( isInterprime ( n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Find the unit place digit of sum of N factorials | C # program to find the unit place digit of the first N natural numbers factorials ; Function to find the unit 's place digit ; Let us write for cases when N is smaller than or equal to 4. ; We know following ( 1 ! + 2 ! + 3 ! + 4 ! ) % 10 = 3 else ( N >= 4 ) ; Driver code
using System ; class GFG { static int get_unit_digit ( int N ) { if ( N == 0 N == 1 ) return 1 ; else if ( N == 2 ) return 3 ; else if ( N == 3 ) return 9 ; return 3 ; } static public void Main ( ) { int N = 1 ; for ( N = 0 ; N <= 10 ; N ++ ) Console . WriteLine ( " For ▁ N ▁ = ▁ " + N + " ▁ : ▁ " + get_unit_digit ( N ) ) ; } }
Sum of squares of Fibonacci numbers | C # Program to find sum of squares of Fibonacci numbers in O ( Log n ) time . ; Returns n 'th Fibonacci number using table f[]  ; Base cases ; If fib ( n ) is already computed ; Applying above formula [ Note value n & 1 is 1 if n is odd , else 0 ] . ; Function to calculate sum of squares of Fibonacci numbers ; Driver Code
using System ; class gfg { int [ ] f = new int [ 1000 ] ; public int fib ( int n ) { if ( n == 0 ) return 0 ; if ( n == 1 n == 2 ) return ( f [ n ] = 1 ) ; if ( f [ n ] > 0 ) return f [ n ] ; int k = ( ( n & 1 ) > 0 ) ? ( n + 1 ) / 2 : n / 2 ; f [ n ] = ( ( n & 1 ) > 0 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; return f [ n ] ; } public int calculateSumOfSquares ( int n ) { return fib ( n ) * fib ( n + 1 ) ; } } class geek { public static int Main ( ) { gfg g = new gfg ( ) ; int n = 6 ; Console . WriteLine ( " Sum ▁ of ▁ Squares ▁ of ▁ Fibonacci ▁ numbers ▁ is ▁ : ▁ { 0 } " , g . calculateSumOfSquares ( n ) ) ; return 0 ; } }
Number of solutions for the equation x + y + z <= n | C # program to find the number of solutions for the equation x + y + z <= n , such that 0 <= x <= X , 0 <= y <= Y , 0 <= z <= Z . ; function to find the number of solutions for the equation x + y + z <= n , such that 0 <= x <= X , 0 <= y <= Y , 0 <= z <= Z . ; to store answer ; for values of x ; for values of y ; maximum possible value of z ; if z value greater than equals to 0 then only it is valid ; find minimum of temp and z ; return required answer ; Driver code
using System ; public class GFG { static int NumberOfSolutions ( int x , int y , int z , int n ) { int ans = 0 ; for ( int i = 0 ; i <= x ; i ++ ) { for ( int j = 0 ; j <= y ; j ++ ) { int temp = n - i - j ; if ( temp >= 0 ) { temp = Math . Min ( temp , z ) ; ans += temp + 1 ; } } } return ans ; } static public void Main ( ) { int x = 1 , y = 2 , z = 3 , n = 4 ; Console . WriteLine ( NumberOfSolutions ( x , y , z , n ) ) ; } }
Program to find the Nth term of series 5 , 12 , 21 , 32 , 45. ... . . | C # program to find the N - th term of the series : 5 , 12 , 21 , 32 , 45. . ... . ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return ( int ) Math . Pow ( n , 2 ) + 4 * n ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Numbers less than N which are product of exactly two distinct prime numbers | C # program to find numbers that are product of exactly two distinct prime numbers ; Function to check whether a number is a PerfectSquare or not ; Function to check if a number is a product of exactly two distinct primes ; Function to find numbers that are product of exactly two distinct prime numbers . ; Vector to store such numbers ; insert in the vector ; Print all numbers till n from the vector ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool isPerfectSquare ( double x ) { double sr = Math . Sqrt ( x ) ; return ( ( sr - Math . Floor ( sr ) ) == 0 ) ; } static bool isProduct ( int num ) { int cnt = 0 ; for ( int i = 2 ; cnt < 2 && i * i <= num ; ++ i ) { while ( num % i == 0 ) { num /= i ; ++ cnt ; } } if ( num > 1 ) ++ cnt ; return cnt == 2 ; } static void findNumbers ( int N ) { List < int > vec = new List < int > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( isProduct ( i ) && ! isPerfectSquare ( i ) ) { vec . Add ( i ) ; } } foreach ( var a in vec ) Console . Write ( a + " ▁ " ) ; } public static void Main ( String [ ] args ) { int N = 30 ; findNumbers ( N ) ; } }
Program to find the Nth term of the series 3 , 20 , 63 , 144 , 230 , â €¦ â €¦ | C # program to find N - th term of the series : 3 , 20 , 63 , 144 , 230 . ... . ; calculate Nth term of series ; return final sum ; Driver code
using System ; class solution { static int nthTerm ( int n ) { return 2 * ( int ) Math . Pow ( n , 3 ) + ( int ) Math . Pow ( n , 2 ) ; } public static void Main ( ) { int N = 3 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Find Nth number of the series 1 , 6 , 15 , 28 , 45 , ... . . | C # program to find N - th term of the series : ; function to return nth term of the series ; Driver Code ; Taking n as 4 ; Printing the nth term
using System ; class GFG { static long NthTerm ( long n ) { long x = ( 2 * n * n ) % 1000000009 ; return ( x - n + 1000000009 ) % 1000000009 ; } public static void Main ( ) { long N = 4 ; Console . WriteLine ( NthTerm ( N ) ) ; } }
Program to print the Sum of series | C # program to find SUM upto N - th term of the series : - 1 , 2 , 11 , 26 , 47 , 74 , ... . . ; calculate Nth term of series ; Driver Code ; Get the value of N ; Get the sum of the series
using System ; class GFG { static int findSum ( int N ) { return ( N * ( N + 1 ) * ( 2 * N - 5 ) + 4 * N ) / 2 ; } static public void Main ( ) { int N = 3 ; Console . Write ( findSum ( N ) ) ; } }
Program to find the Nth term of series | C # program to find N - th term of the series : 9 , 23 , 45 , 75 , 113 , 159. . ... . ; calculate Nth term of series ; Driver code ; Get the value of N ; Find the Nth term and print it
using System ; class GFG { static int nthTerm ( int N ) { return ( ( 3 * N * N ) - ( 6 * N ) + 2 ) ; } public static void Main ( ) { int N = 3 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Program to find the value of tan ( nÎ ˜ ) | C # program to find the value of cos ( n - theta ) ; This function use to calculate the binomial coefficient upto 15 ; use simple DP to find coefficient ; Function to find the value of ; store required answer ; use to toggle sign in sequence . ; calculate numerator ; calculate denominator ; Driver code
using System ; public class GFG { private static int MAX = 16 ; static long [ , ] nCr = new long [ MAX , MAX ] ; static void binomial ( ) { for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i , j ] = 1 ; else nCr [ i , j ] = nCr [ i - 1 , j ] + nCr [ i - 1 , j - 1 ] ; } } } static double findTanNTheta ( double tanTheta , int n ) { double ans = 0 , numerator = 0 , denominator = 0 ; long toggle = 1 ; for ( int i = 1 ; i <= n ; i += 2 ) { numerator = numerator + nCr [ n , i ] * Math . Pow ( tanTheta , i ) * toggle ; toggle = toggle * - 1 ; } denominator = 1 ; toggle = - 1 ; for ( int i = 2 ; i <= n ; i += 2 ) { numerator = numerator + nCr [ n , i ] * Math . Pow ( tanTheta , i ) * toggle ; toggle = toggle * - 1 ; } ans = numerator / denominator ; return ans ; } public static void Main ( ) { binomial ( ) ; double tanTheta = 0.3 ; int n = 10 ; Console . Write ( findTanNTheta ( tanTheta , n ) ) ; } }
Check if any large number is divisible by 19 or not | C # Program to validate the above logic ; Function to check if the number is divisible by 19 or not ; Extracting the last digit ; Truncating the number ; Subtracting the five times the last digit from the remaining number ; Return n is divisible by 19 ; Driver code
using System ; class GFG { static bool isDivisible ( long n ) { while ( n / 100 > 0 ) { long d = n % 10 ; n /= 10 ; n += d * 2 ; } return ( n % 19 == 0 ) ; } public static void Main ( ) { long n = 101156 ; if ( isDivisible ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to find Sum of the series 1 * 3 + 3 * 5 + ... . | C # program to find sum of first n terms ; Sn = n * ( 4 * n * n + 6 * n - 1 ) / 3 ; Driver code ; number of terms to be included in the sum ; find the Sn
using System ; class GFG { static int calculateSum ( int n ) { return ( n * ( 4 * n * n + 6 * n - 1 ) / 3 ) ; } static public void Main ( ) { int n = 4 ; Console . WriteLine ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }
Triplet with no element divisible by 3 and sum N | C # program to print a , b and c such that a + b + c = N ; Function to print a , b and c ; first loop ; check for 1 st number ; second loop ; check for 2 nd number ; third loop ; Check for 3 rd number ; Driver Code
class GFG { static void printCombination ( int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( i % 3 != 0 ) { for ( int j = 1 ; j < n ; j ++ ) { if ( j % 3 != 0 ) { for ( int k = 1 ; k < n ; k ++ ) { if ( k % 3 != 0 && ( i + j + k ) == n ) { System . Console . WriteLine ( i + " ▁ " + j + " ▁ " + k ) ; return ; } } } } } } } static void Main ( ) { int n = 233 ; printCombination ( n ) ; } }
Program to find the percentage of difference between two numbers | C # program to calculate the percentage ; Function to calculate the percentage ; Driver Code ; Function calling
class GFG { static int percent ( int a , int b ) { float result = 0 ; result = ( ( b - a ) * 100 ) / a ; return ( int ) result ; } static void Main ( ) { int a = 20 , b = 25 ; System . Console . WriteLine ( percent ( a , b ) + " % " ) ; } }
Numbers with sum of digits equal to the sum of digits of its all prime factor | C # program to Find the count of the numbers in the given range such that the sum of its digit is equal to the sum of all its prime factors digits sum . ; maximum size of number ; array to store smallest prime factor of number ; array to store sum of digits of a number ; boolean array to check given number is countable for required answer or not . ; prefix array to store answer ; Calculating SPF ( SmallestPrime Factor ) for every number till MAXN . ; marking 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 numbers divisible by i ; marking spf [ j ] if it is not previously marked ; Function to find sum of digits in a number ; find sum of digits of all numbers up to MAXN ; add sum of digits of least prime factor and n / spf [ n ] ; if it is valid make isValid true ; prefix sum to compute answer ; Driver code ; declaration ; print answer for required range ; print answer for required range
using System ; class GFG { static int MAXN = 100005 ; static int [ ] spf = new int [ MAXN ] ; static int [ ] sum_digits = new int [ MAXN ] ; static bool [ ] isValid = new bool [ MAXN ] ; static int [ ] ans = new int [ MAXN ] ; static void Smallest_prime_factor ( ) { for ( int i = 1 ; i < MAXN ; i ++ ) spf [ i ] = i ; for ( int i = 4 ; i < MAXN ; i += 2 ) spf [ i ] = 2 ; for ( int i = 3 ; i * i <= MAXN ; i += 2 ) if ( spf [ i ] == i ) for ( int j = i * i ; j < MAXN ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } static int Digit_Sum ( int copy ) { int d = 0 ; while ( copy > 0 ) { d += copy % 10 ; copy /= 10 ; } return d ; } static void Sum_Of_All_Digits ( ) { for ( int n = 2 ; n < MAXN ; n ++ ) { sum_digits [ n ] = sum_digits [ n / spf [ n ] ] + Digit_Sum ( spf [ n ] ) ; if ( Digit_Sum ( n ) == sum_digits [ n ] ) isValid [ n ] = true ; } for ( int n = 2 ; n < MAXN ; n ++ ) { if ( isValid [ n ] ) ans [ n ] = 1 ; ans [ n ] += ans [ n - 1 ] ; } } public static void Main ( ) { Smallest_prime_factor ( ) ; Sum_Of_All_Digits ( ) ; int l , r ; l = 2 ; r = 3 ; Console . WriteLine ( " Valid ▁ numbers ▁ in ▁ the ▁ range ▁ " + l + " ▁ " + r + " ▁ are ▁ " + ( ans [ r ] - ans [ l - 1 ] ) ) ; l = 2 ; r = 10 ; Console . WriteLine ( " Valid ▁ numbers ▁ in ▁ the ▁ range ▁ " + l + " ▁ " + r + " ▁ are ▁ " + ( ans [ r ] - ans [ l - 1 ] ) ) ; } }
Count numbers which can be represented as sum of same parity primes | C # program to Count numbers which can be represented as sum of same parity primes ; Function to calculate count ; Driver code
using System ; class GFG { public static int calculate ( int [ ] ar , int size ) { int count = 0 ; for ( int i = 0 ; i < size ; i ++ ) if ( ar [ i ] % 2 == 0 && ar [ i ] != 0 && ar [ i ] != 2 ) count ++ ; return count ; } static public void Main ( String [ ] args ) { int [ ] a = { 1 , 3 , 4 , 6 } ; int size = a . Length ; Console . WriteLine ( calculate ( a , size ) ) ; } }
N | C # program to answer queries for N - th prime factor of a number ; 2 - D vector that stores prime factors ; Function to pre - store prime factors of all numbers till 10 ^ 6 ; calculate unique prime factors for every number till 10 ^ 6 ; find prime factors ; store if prime factor ; Function that returns answer for every query ; Driver Code ; Function to pre - store unique prime factors ; 1 st query ; 2 nd query ; 3 rd query ; 4 th query
using System ; using System . Collections . Generic ; class GFG { static int N = 100001 ; static List < int > [ ] v = new List < int > [ N ] ; static void preprocess ( ) { for ( int i = 1 ; i < N ; i ++ ) { int num = i ; for ( int j = 2 ; j <= Math . Sqrt ( num ) ; j ++ ) { if ( num % j == 0 ) { v [ i ] . Add ( j ) ; while ( num % j == 0 ) { num = num / j ; } } } if ( num > 2 ) v [ i ] . Add ( num ) ; } } static int query ( int number , int n ) { return v [ number ] [ n - 1 ] ; } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < N ; i ++ ) v [ i ] = new List < int > ( ) ; preprocess ( ) ; int number = 6 , n = 1 ; Console . Write ( query ( number , n ) + " STRNEWLINE " ) ; number = 210 ; n = 3 ; Console . Write ( query ( number , n ) + " STRNEWLINE " ) ; number = 210 ; n = 2 ; Console . Write ( query ( number , n ) + " STRNEWLINE " ) ; number = 60 ; n = 2 ; Console . Write ( query ( number , n ) + " STRNEWLINE " ) ; } }