codeparrot/xlcost-text-to-code huggingface dataset:
Perfect Cube factors of a Number | C # program for the above approach ; Function that returns the count of factors that are perfect cube ; To store the count of number of times a prime number divides N . ; To store the number of factors that are perfect cube ; Count number of 2 's that divides N ; Calculate ans according to above formula ; Check for all the possible numbers that can divide it ; Loop to check the number of times prime number i divides it ; Calculate ans according to above formula ; Return final count ; Driver Code ; Given number ; Function call
using System ; class GFG { static int noOfFactors ( int N ) { if ( N == 1 ) return 1 ; int count = 0 ; int ans = 1 ; while ( N % 2 == 0 ) { count ++ ; N = N / 2 ; } ans *= ( count / 3 + 1 ) ; for ( int i = 3 ; i * i <= N ; i = i + 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = N / i ; } ans *= ( count / 3 + 1 ) ; } return ans ; } public static void Main ( String [ ] args ) { int N = 216 ; Console . Write ( noOfFactors ( N ) ) ; } }
Efficient program to print the number of factors of n numbers | C # program to count number of factors of an array of integers ; function to generate all prime factors of numbers from 1 to 10 ^ 6 ; Initializes all the positions with their value . ; Initializes all multiples of 2 with 2 ; A modified version of Sieve of Eratosthenes to store the smallest prime factor that divides every number . ; check if it has no prime factor . ; Initializes of j starting from i * i ; if it has no prime factor before , then stores the smallest prime divisor ; function to calculate number of factors ; stores the smallest prime number that divides n ; stores the count of number of times a prime number divides n . ; reduces to the next number after prime factorization of n ; false when prime factorization is done ; if the same prime number is dividing n , then we increase the count ; if its a new prime factor that is factorizing n , then we again set c = 1 and change dup to the new prime factor , and apply the formula explained above . ; prime factorizes a number ; for the last prime factor ; Driver program to test above function ; array to store prime factors ; generate prime factors of number upto 10 ^ 6
using System ; class GFG { static int MAX = 1000001 ; static int [ ] factor ; static void generatePrimeFactors ( ) { factor [ 1 ] = 1 ; for ( int i = 2 ; i < MAX ; i ++ ) factor [ i ] = i ; for ( int i = 4 ; i < MAX ; i += 2 ) factor [ i ] = 2 ; for ( int i = 3 ; i * i < MAX ; i ++ ) { if ( factor [ i ] == i ) { for ( int j = i * i ; j < MAX ; j += i ) { if ( factor [ j ] == j ) factor [ j ] = i ; } } } } static int calculateNoOFactors ( int n ) { if ( n == 1 ) return 1 ; int ans = 1 ; int dup = factor [ n ] ; int c = 1 ; int j = n / factor [ n ] ; while ( j != 1 ) { if ( factor [ j ] == dup ) c += 1 ; else { dup = factor [ j ] ; ans = ans * ( c + 1 ) ; c = 1 ; } j = j / factor [ j ] ; } ans = ans * ( c + 1 ) ; return ans ; } public static void Main ( ) { factor = new int [ MAX ] ; factor [ 0 ] = 0 ; generatePrimeFactors ( ) ; int [ ] a = { 10 , 30 , 100 , 450 , 987 } ; int q = a . Length ; for ( int i = 0 ; i < q ; i ++ ) Console . Write ( calculateNoOFactors ( a [ i ] ) + " ▁ " ) ; } }
Digit | C # program for Digit Product Sequence ; function to produce and print Digit Product Sequence ; Array which store sequence ; Temporary variable to store product ; Initialize first element of the array with 1 ; Run a loop from 1 to N . Check if previous number is single digit or not . If yes then product = 1 else take modulus . Then again check if previous number is single digit or not if yes then store previous number , else store its first value Then for every i store value in the array . ; Print sequence ; Driver Code ; Value of N ; Calling function
using System ; class GFG { public static void digit_product_Sum ( int N ) { int [ ] a = new int [ N + 1 ] ; int product = 1 ; a [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { product = a [ i - 1 ] / 10 ; if ( product == 0 ) product = 1 ; else product = a [ i - 1 ] % 10 ; int val = a [ i - 1 ] / 10 ; if ( val == 0 ) val = a [ i - 1 ] ; a [ i ] = a [ i - 1 ] + ( val * product ) ; } for ( int i = 0 ; i < N ; i ++ ) Console . Write ( a [ i ] + " ▁ " ) ; } public static void Main ( ) { int N = 10 ; digit_product_Sum ( N ) ; } }
Geometric mean ( Two Methods ) | Program to calculate the geometric mean of the given array elements . ; function to calculate geometric mean and return float value . ; declare product variable and initialize it to 1. ; Compute the product of all the elements in the array . ; compute geometric mean through formula pow ( product , 1 / n ) and return the value to main function . ; Driver function
using System ; class GFG { static float geometricMean ( int [ ] arr , int n ) { float product = 1 ; for ( int i = 0 ; i < n ; i ++ ) product = product * arr [ i ] ; float gm = ( float ) Math . Pow ( product , ( float ) 1 / n ) ; return gm ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ; int n = arr . Length ; Console . WriteLine ( geometricMean ( arr , n ) ) ; } }
Check whether a number can be expressed as a product of single digit numbers | C # implementation to check whether a number can be expressed as a product of single digit numbers ; Number of single digit prime numbers ; function to check whether a number can be expressed as a product of single digit numbers ; if ' n ' is a single digit number , then it can be expressed ; define single digit prime numbers array ; repeatedly divide ' n ' by the given prime numbers until all the numbers are used or ' n ' > 1 ; if true , then ' n ' can be expressed ; Driver program to test above
using System ; class GFG { static int SIZE = 4 ; static bool productOfSingelDgt ( int n ) { if ( n >= 0 && n <= 9 ) return true ; int [ ] prime = { 2 , 3 , 5 , 7 } ; for ( int i = 0 ; i < SIZE && n > 1 ; i ++ ) while ( n % prime [ i ] == 0 ) n = n / prime [ i ] ; return ( n == 1 ) ; } public static void Main ( ) { int n = 24 ; if ( productOfSingelDgt ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to find sum of first n natural numbers | Efficient C # program to find sum of first n natural numbers . ; Returns sum of first n natural numbers ; Driver code
using System ; class GFG { static int findSum ( int n ) { return n * ( n + 1 ) / 2 ; } public static void Main ( ) { int n = 5 ; Console . Write ( findSum ( n ) ) ; } }
Program to find sum of first n natural numbers | Efficient C # program to find the sum of first n natural numbers that avoid overflow if result is going to be within limits . ; Returns sum of first n natural numbers ; If n is odd , ( n + 1 ) must be even ; Driver code
using System ; class GFG { static int findSum ( int n ) { if ( n % 2 == 0 ) return ( n / 2 ) * ( n + 1 ) ; else return ( ( n + 1 ) / 2 ) * n ; } public static void Main ( ) { int n = 5 ; Console . Write ( findSum ( n ) ) ; } }
Maximum number of unique prime factors | C # program to find maximum number of prime factors in first N natural numbers ; Return maximum number of prime factors for any number in [ 1 , N ] ; Based on Sieve of Eratosthenes ; If p is prime ; We simply multiply first set of prime numbers while the product is smaller than N . ; Driver Code
using System ; class GFG { static int maxPrimefactorNum ( int N ) { if ( N < 2 ) return 0 ; bool [ ] arr = new bool [ N + 1 ] ; int prod = 1 , res = 0 ; for ( int p = 2 ; p * p <= N ; p ++ ) { if ( arr [ p ] == false ) { for ( int i = p * 2 ; i <= N ; i += p ) arr [ i ] = true ; prod *= p ; if ( prod > N ) return res ; res ++ ; } } return res ; } public static void Main ( ) { int N = 500 ; Console . WriteLine ( maxPrimefactorNum ( N ) ) ; } }
Program to print multiplication table of a number | C # program to print table over given range . ; Driver code ; Change here to change input number ; Change here to change result
using System ; class GFG { public static void Main ( ) { int n = 8 ; int range = 12 ; for ( int i = 1 ; i <= range ; ++ i ) Console . Write ( n + " ▁ * ▁ " + i + " ▁ = ▁ " + n * i + " STRNEWLINE " ) ; } }
To check a number is palindrome or not without using any extra space | C # program to find number is palindrome or not without using any extra space ; Function to check if given number is palindrome or not without using the extra space ; Find the appropriate divisor to extract the leading digit ; If first and last digit not same return false ; Removing the leading and trailing digit from number ; Reducing divisor by a factor of 2 as 2 digits are dropped ; Driver code
using System ; class GFG { static bool isPalindrome ( int n ) { int divisor = 1 ; while ( n / divisor >= 10 ) divisor *= 10 ; while ( n != 0 ) { int leading = n / divisor ; int trailing = n % 10 ; if ( leading != trailing ) return false ; n = ( n % divisor ) / 10 ; divisor = divisor / 100 ; } return true ; } static public void Main ( ) { if ( isPalindrome ( 1001 ) ) Console . WriteLine ( " Yes , ▁ it ▁ " + " is ▁ Palindrome " ) ; else Console . WriteLine ( " No , ▁ not ▁ " + " Palindrome " ) ; } }
Find whether a given integer is a power of 3 or not | C # program to check if a number is power of 3 or not . ; Returns true if n is power of 3 , else false ; The maximum power of 3 value that integer can hold is 1162261467 ( 3 ^ 19 ) . ; Driver code
using System ; public class GFG { static bool check ( int n ) { if ( n <= 0 ) return false ; return 1162261467 % n == 0 ; } public static void Main ( ) { int n = 9 ; if ( check ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Demlo number ( Square of 11. . .1 ) | C # program to print DemloNumber ; To return demlo number . This function assumes that the length of str is smaller than 10. ; Add numbers to res upto size of str and then add number reverse to it ; Driver program to test printDemlo ( )
using System ; public class GFG { static String printDemlo ( String str ) { int len = str . Length ; String res = " " ; for ( int i = 1 ; i <= len ; i ++ ) res += i . ToString ( ) ; for ( int i = len - 1 ; i >= 1 ; i -- ) res += i . ToString ( ) ; return res ; } public static void Main ( ) { String str = "111111" ; Console . WriteLine ( printDemlo ( str ) ) ; } }
Discrete Cosine Transform ( Algorithm and Program ) | C # program to perform discrete cosine transform ; Function to find discrete cosine transform and print it ; dct will store the discrete cosine transform ; ci and cj depends on frequency as well as number of row and columns of specified matrix ; sum will temporarily store the sum of cosine signals ; Driver code
using System ; class GFG { public static void dctTransform ( int [ , ] matrix , int m , int n ) { double pi = 3.142857 ; int i , j , k , l ; double [ , ] dct = new double [ m , n ] ; double ci , cj , dct1 , sum ; for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( i == 0 ) ci = 1 / Math . Sqrt ( m ) ; else ci = Math . Sqrt ( 2 ) / Math . Sqrt ( m ) ; if ( j == 0 ) cj = 1 / Math . Sqrt ( n ) ; else cj = Math . Sqrt ( 2 ) / Math . Sqrt ( n ) ; sum = 0 ; for ( k = 0 ; k < m ; k ++ ) { for ( l = 0 ; l < n ; l ++ ) { dct1 = matrix [ k , l ] * Math . Cos ( ( 2 * k + 1 ) * i * pi / ( 2 * m ) ) * Math . Cos ( ( 2 * l + 1 ) * j * pi / ( 2 * n ) ) ; sum = sum + dct1 ; } } dct [ i , j ] = ci * cj * sum ; } } for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { Console . Write ( dct [ i , j ] ) ; } Console . WriteLine ( ) ; } } static void Main ( ) { const int m = 8 , n = 8 ; int [ , ] matrix = new int [ m , n ] { { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } , { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 } } ; dctTransform ( matrix , m , n ) ; } }
Number of times a number can be replaced by the sum of its digits until it only contains one digit | C # program to count number of times we need to add digits to get a single digit . ; Here the count variable store how many times we do sum of digits and temporary_sum always store the temporary sum we get at each iteration . ; In this loop we always compute the sum of digits in temporary_ sum variable and convert it into string str till its length become 1 and increase the count in each iteration . ; computing sum of its digits ; converting temporary_sum into string str again . ; increase the count ; Driver code
using System ; class GFG { static int NumberofTimes ( String str ) { int temporary_sum = 0 , count = 0 ; while ( str . Length > 1 ) { temporary_sum = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) temporary_sum += ( str [ i ] - '0' ) ; str = temporary_sum + " " ; count ++ ; } return count ; } public static void Main ( ) { String s = "991" ; Console . Write ( NumberofTimes ( s ) ) ; } }
Climb n | C # program to count total number of ways to reach n - th stair with all jumps allowed ; Function to calculate leaps ; Driver code
using System ; class GFG { static int calculateLeaps ( int n ) { if ( n == 0 n == 1 ) { return 1 ; } else { int leaps = 0 ; for ( int i = 0 ; i < n ; i ++ ) leaps += calculateLeaps ( i ) ; return leaps ; } } public static void Main ( ) { Console . WriteLine ( calculateLeaps ( 4 ) ) ; } }
Print last k digits of a ^ b ( a raised to power b ) | C # code to find last k digits of a ^ b ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; Initialize result ; x = x % p ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Method to print last k digits of a ^ b ; Generating 10 ^ k ; Calling modular exponentiation ; Printing leftmost zeros . Since ( a ^ b ) % k can have digits less then k . In that case we need to print zeros ; If temp is not zero then print temp If temp is zero then already printed ; Driver Code
using System ; class GFG { static int power ( long x , long y , long p ) { long res = 1 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return ( int ) res ; } static void printLastKDigits ( int a , int b , int k ) { Console . Write ( " Last ▁ " + k + " ▁ digits ▁ of ▁ " + a + " ^ " + b + " ▁ = ▁ " ) ; int temp = 1 ; for ( int i = 1 ; i <= k ; i ++ ) temp *= 10 ; temp = power ( a , b , temp ) ; for ( int i = 0 ; i < k - temp . ToString ( ) . Length ; i ++ ) Console . WriteLine ( 0 ) ; if ( temp != 0 ) Console . Write ( temp ) ; } public static void Main ( ) { int a = 11 ; int b = 3 ; int k = 2 ; printLastKDigits ( a , b , k ) ; } }
Adam Number | C # Program to Check Adam Number ; To reverse Digits of numbers ; To square number ; To check Adam Number ; Square first number and square reverse digits of second number ; If reverse of b equals a then given number is Adam number ; Driver Code
using System ; public class main { static int reverseDigits ( int num ) { int rev = 0 ; while ( num > 0 ) { rev = rev * 10 + num % 10 ; num /= 10 ; } return rev ; } static int square ( int num ) { return ( num * num ) ; } static bool checkAdamNumber ( int num ) { int a = square ( num ) ; int b = square ( reverseDigits ( num ) ) ; if ( a == reverseDigits ( b ) ) return true ; return false ; } public static void Main ( String [ ] args ) { int num = 12 ; if ( checkAdamNumber ( num ) ) Console . WriteLine ( " Adam ▁ Number " ) ; else Console . WriteLine ( " Not ▁ a ▁ Adam ▁ Number " ) ; } }
Count total number of digits from 1 to n | C # program to count total number of digits we have to write from 1 to n ; number_of_digits store total digits we have to write ; In the loop we are decreasing 0 , 9 , 99 ... from n till ( n - i + 1 ) is greater than 0 and sum them to number_of_digits to get the required sum ; Driver Method
using System ; public class GFG { static int totalDigits ( int n ) { int number_of_digits = 0 ; for ( int i = 1 ; i <= n ; i *= 10 ) number_of_digits += ( n - i + 1 ) ; return number_of_digits ; } public static void Main ( ) { int n = 13 ; Console . WriteLine ( totalDigits ( n ) ) ; } }
Numbers with exactly 3 divisors | C # program to print all three - primes smaller than or equal to n using Sieve of Eratosthenes ; Generates all primes upto n and prints their squares ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; print squares of primes upto n ; Driver program
class GFG { static void numbersWith3Divisors ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; prime [ 0 ] = prime [ 1 ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == false ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = true ; } } System . Console . WriteLine ( " Numbers ▁ with ▁ 3 ▁ divisors ▁ : ▁ " ) ; for ( int i = 0 ; i * i <= n ; i ++ ) if ( ! prime [ i ] ) System . Console . Write ( i * i + " ▁ " ) ; } public static void Main ( ) { int n = 96 ; numbersWith3Divisors ( n ) ; } }
Program for decimal to hexadecimal conversion | C # program to convert a decimal number to hexadecimal number ; function to convert decimal to hexadecimal ; char array to store hexadecimal number ; counter for hexadecimal number array ; temporary variable to store remainder ; storing remainder in temp variable . ; check if temp < 10 ; printing hexadecimal number array in reverse order ; Driver Code
using System ; class GFG { static void decToHexa ( int n ) { char [ ] hexaDeciNum = new char [ 100 ] ; int i = 0 ; while ( n != 0 ) { int temp = 0 ; temp = n % 16 ; if ( temp < 10 ) { hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ; i ++ ; } else { hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ; i ++ ; } n = n / 16 ; } for ( int j = i - 1 ; j >= 0 ; j -- ) Console . Write ( hexaDeciNum [ j ] ) ; } public static void Main ( String [ ] args ) { int n = 2545 ; decToHexa ( n ) ; } }
Program for Decimal to Binary Conversion | C # program to convert a decimal number to binary number ; function to convert decimal to binary ; array to store binary number ; counter for binary array ; storing remainder in binary array ; printing binary array in reverse order ; Driver Code
using System ; public class GFG { static void decToBinary ( int n ) { int [ ] binaryNum = new int [ 32 ] ; int i = 0 ; while ( n > 0 ) { binaryNum [ i ] = n % 2 ; n = n / 2 ; i ++ ; } for ( int j = i - 1 ; j >= 0 ; j -- ) Console . Write ( binaryNum [ j ] ) ; } public static void Main ( ) { int n = 17 ; decToBinary ( n ) ; } }
Break the number into three parts | C # program to count number of ways to break a number in three parts ; Function to count number of ways to make the given number n ; driver program
using System ; class GFG { static long count_of_ways ( long n ) { long count = 0 ; count = ( n + 1 ) * ( n + 2 ) / 2 ; return count ; } public static void Main ( ) { long n = 3 ; Console . WriteLine ( count_of_ways ( n ) ) ; } }
Implement * , | C # code to illustrate * , - , / using only ' + ' arithmetic operator ; Function to flip the sign using only " + " operator ( It is simple with ' * ' allowed . We need to do a = ( - 1 ) * a ; If sign is + ve turn it - ve and vice - versa ; Check if a and b are of different signs ; Function to subtract two numbers by negating b and adding them ; Negating b ; Function to multiply a by b by adding a to itself b times ; because algo is faster if b < a ; Adding a to itself b times ; Check if final sign must be - ve or + ve ; Function to divide a by b by counting how many times ' b ' can be subtracted from ' a ' before getting 0 ; Raise exception if b is 0 ; Negating b to subtract from a ; Subtracting divisor from dividend ; Check if a and b are of similar symbols or not ; Driver code
using System ; class GFG { static int flipSign ( int a ) { int neg = 0 ; int tmp = a < 0 ? 1 : - 1 ; while ( a != 0 ) { neg += tmp ; a += tmp ; } return neg ; } static bool areDifferentSign ( int a , int b ) { return ( ( a < 0 && b > 0 ) || ( a > 0 && b < 0 ) ) ; } static int sub ( int a , int b ) { return a + flipSign ( b ) ; } static int mul ( int a , int b ) { if ( a < b ) return mul ( b , a ) ; int sum = 0 ; for ( int i = Math . Abs ( b ) ; i > 0 ; i -- ) sum += a ; if ( b < 0 ) sum = flipSign ( sum ) ; return sum ; } static int division ( int a , int b ) { if ( b == 0 ) throw new ArithmeticException ( ) ; int quotient = 0 , dividend ; int divisor = flipSign ( Math . Abs ( b ) ) ; for ( dividend = Math . Abs ( a ) ; dividend >= Math . Abs ( divisor ) ; dividend += divisor ) quotient ++ ; if ( areDifferentSign ( a , b ) ) quotient = flipSign ( quotient ) ; return quotient ; } public static void Main ( ) { Console . WriteLine ( " Subtraction ▁ is ▁ " + sub ( 4 , - 2 ) ) ; Console . WriteLine ( " Product ▁ is ▁ " + mul ( - 9 , 6 ) ) ; try { Console . WriteLine ( " Division ▁ is ▁ " + division ( 8 , 2 ) ) ; } catch ( Exception ) { Console . WriteLine ( " Exception ▁ : - ▁ Divide ▁ by ▁ 0" ) ; } } }
Number of Groups of Sizes Two Or Three Divisible By 3 | C # Program to find groups of 2 or 3 whose sum is divisible by 3 ; Initialize groups to 0 ; Increment group with specified remainder ; Return groups using the formula ; Driver code
using System ; class GFG { static int numOfCombinations ( int [ ] arr , int N ) { int [ ] C = { 0 , 0 , 0 } ; for ( int i = 0 ; i < N ; ++ i ) ++ C [ arr [ i ] % 3 ] ; return C [ 1 ] * C [ 2 ] + C [ 0 ] * ( C [ 0 ] - 1 ) / 2 + C [ 0 ] * ( C [ 0 ] - 1 ) * ( C [ 0 ] - 2 ) / 6 + C [ 1 ] * ( C [ 1 ] - 1 ) * ( C [ 1 ] - 2 ) / 6 + C [ 2 ] * ( C [ 2 ] - 1 ) * ( C [ 2 ] - 2 ) / 6 + C [ 0 ] * C [ 1 ] * C [ 2 ] ; } public static void Main ( ) { int [ ] arr1 = { 1 , 5 , 7 , 2 , 9 , 14 } ; Console . WriteLine ( numOfCombinations ( arr1 , 6 ) ) ; int [ ] arr2 = { 3 , 6 , 9 , 12 } ; Console . WriteLine ( numOfCombinations ( arr2 , 4 ) ) ; } }
Check if a number can be written as a sum of ' k ' prime numbers | C # implementation to check if N can be written as sum of k primes ; Checking if a number is prime or not ; check for numbers from 2 to sqrt ( x ) if it is divisible return false ; Returns true if N can be written as sum of K primes ; N < 2 K directly return false ; If K = 1 return value depends on primality of N ; if N is even directly return true ; ; If N is odd , then one prime must be 2. All other primes are odd and cannot have a pair sum as even . ; If K >= 3 return true ; ; Driver function
using System ; class GFG { static bool isprime ( int x ) { for ( int i = 2 ; i * i <= x ; i ++ ) if ( x % i == 0 ) return false ; return true ; } static bool isSumOfKprimes ( int N , int K ) { if ( N < 2 * K ) return false ; if ( K == 1 ) return isprime ( N ) ; if ( K == 2 ) { if ( N % 2 == 0 ) return true ; return isprime ( N - 2 ) ; } return true ; } public static void Main ( ) { int n = 10 , k = 2 ; if ( isSumOfKprimes ( n , k ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Count total divisors of A or B in a given range | C # program to count total divisors of ' a ' or ' b ' in a given range ; Utility function to find GCD of two numbers ; Utility function to find LCM of two numbers ; Function to calculate all divisors in given range ; Find LCM of a and b ; Find common divisor by using LCM ; Driver code
using System ; class GFG { static int GCD ( int num1 , int num2 ) { int Remainder ; while ( num2 != 0 ) { Remainder = num1 % num2 ; num1 = num2 ; num2 = Remainder ; } return num1 ; } static int FindLCM ( int a , int b ) { return ( a * b ) / GCD ( a , b ) ; } static int rangeDivisor ( int m , int n , int a , int b ) { int lcm = FindLCM ( a , b ) ; int a_divisor = n / a - ( m - 1 ) / a ; int b_divisor = n / b - ( m - 1 ) / b ; int common_divisor = n / lcm - ( m - 1 ) / lcm ; int ans = a_divisor + b_divisor - common_divisor ; return ans ; } public static void Main ( ) { int m = 3 , n = 11 , a = 2 , b = 3 ; Console . WriteLine ( rangeDivisor ( m , n , a , b ) ) ; m = 11 ; n = 1000000 ; a = 6 ; b = 35 ; Console . WriteLine ( rangeDivisor ( m , n , a , b ) ) ; } }