codeparrot/xlcost-text-to-code huggingface dataset:
Ulam Number Sequence | C # code to print nth Ulam number ; Array to store Ulam Number ; function to compute ulam Number ; Set to search specific Ulam number efficiently ; push First 2 two term of the sequence in the array and set for further calculation ; loop to generate Ulam number ; traverse the array and check if i can be represented as sum of two distinct element of the array ; Check if i - arr [ j ] exist in the array or not using set If yes , Then i can be represented as sum of arr [ j ] + ( i - arr [ j ] ) ; if Count is greater than 2 break the loop ; If count is 2 that means i can be represented as sum of two distinct terms of the sequence ; i is ulam number ; Driver code ; pre compute Ulam Number sequence ; print nth Ulam number
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 10000 ; static List < int > arr = new List < int > ( ) ; static void ulam ( ) { HashSet < int > s = new HashSet < int > ( ) ; arr . Add ( 1 ) ; s . Add ( 1 ) ; arr . Add ( 2 ) ; s . Add ( 2 ) ; for ( int i = 3 ; i < MAX ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < arr . Count ; j ++ ) { if ( s . Contains ( i - arr [ j ] ) && arr [ j ] != ( i - arr [ j ] ) ) count ++ ; if ( count > 2 ) break ; } if ( count == 2 ) { arr . Add ( i ) ; s . Add ( i ) ; } } } public static void Main ( String [ ] args ) { ulam ( ) ; int n = 9 ; Console . WriteLine ( arr [ n - 1 ] ) ; } }
Hilbert Number | C # program to find nth hilbert Number ; Utility function to return Nth Hilbert Number ; Driver code
using System ; class GFG { static long nthHilbertNumber ( int n ) { return 4 * ( n - 1 ) + 1 ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( nthHilbertNumber ( n ) ) ; } }
Program to find the nth Kynea number | C # code to find nth Kynea number ; Function to calculate nth kynea number ; Firstly calculate 2 ^ n + 1 ; Now calculate ( 2 ^ n + 1 ) ^ 2 ; Now calculate ( ( 2 ^ n + 1 ) ^ 2 ) - 2 ; return nth Kynea number ; Driver Program ; print nth kynea number
using System ; class GFG { static long nthKyneaNumber ( int n ) { n = ( 1 << n ) + 1 ; n = n * n ; n = n - 2 ; return n ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( nthKyneaNumber ( n ) ) ; } }
Program to find the nth Kynea number | C # code to find nth Kynea number ; Function to calculate nth kynea number ; Calculate nth kynea number ; Driver Program ; print nth kynea number
using System ; class GFG { static long nthKyneaNumber ( int n ) { return ( ( 1 << ( 2 * n ) ) + ( 1 << ( n + 1 ) ) - 1 ) ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( nthKyneaNumber ( n ) ) ; } }
Program to check whether a number is Proth number or not | C # program to check Proth number ; Utility function to check power of two ; Function to check if the Given number is Proth number or not ; check if k divides n or not ; Check if n / k is power of 2 or not ; update k to next odd number ; If we reach here means there exists no value of K Such that k is odd number and n / k is a power of 2 greater than k ; Driver code ; Get n ; Check n for Proth Number
using System ; class GFG { static bool isPowerOfTwo ( int n ) { return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) ; } static bool isProthNumber ( int n ) { int k = 1 ; while ( k < ( n / k ) ) { if ( n % k == 0 ) { if ( isPowerOfTwo ( n / k ) ) return true ; } k = k + 2 ; } return false ; } public static void Main ( ) { int n = 25 ; if ( isProthNumber ( n - 1 ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Find last two digits 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 ▁ and ▁ ten ' s place digit ; Let us write for cases when N is smaller than or equal to 10. ; We know following ( 1 ! + 2 ! + 3 ! + 4 ! ... + 10 ! ) % 100 = 13 else ( N >= 10 ) ; Driver code
using System ; class GFG { static int get_last_two_digit ( long N ) { if ( N <= 10 ) { long ans = 0 , fac = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { fac = fac * i ; ans += fac ; } return ( int ) ans % 100 ; } return 13 ; } public static void Main ( ) { long N = 1 ; for ( N = 1 ; N <= 10 ; N ++ ) Console . WriteLine ( " For ▁ N ▁ = ▁ " + N + " ▁ : ▁ " + get_last_two_digit ( N ) ) ; } }
Check whether product of ' n ' numbers is even or odd | C # implementation to check whether product of ' n ' numbers is even or odd ; function to check whether product of ' n ' numbers is even or odd ; if a single even number is found , then final product will be an even number ; product is an odd number ; Driver code
using System ; class GFG { static bool isProductEven ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( ( arr [ i ] & 1 ) == 0 ) return true ; return false ; } public static void Main ( ) { int [ ] arr = { 2 , 4 , 3 , 5 } ; int n = arr . Length ; if ( isProductEven ( arr , n ) ) Console . WriteLine ( " Even " ) ; else Console . WriteLine ( " Odd " ) ; } }
Sum of squares of Fibonacci numbers | C # Program to find sum of squares of Fibonacci numbers ; Function to calculate sum of squares of Fibonacci numbers ; Initialize result ; Add remaining terms ; Driver code
using System ; public class Improve { static int calculateSquareSum ( int n ) { if ( n <= 0 ) return 0 ; int [ ] fibo = new int [ n + 1 ] ; fibo [ 0 ] = 0 ; fibo [ 1 ] = 1 ; int sum = ( fibo [ 0 ] * fibo [ 0 ] ) + ( fibo [ 1 ] * fibo [ 1 ] ) ; for ( int i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; sum += ( fibo [ i ] * fibo [ i ] ) ; } return sum ; } public static void Main ( ) { int n = 6 ; Console . Write ( " Sum ▁ of ▁ squares ▁ of ▁ Fibonacci ▁ numbers ▁ is ▁ : ▁ " + calculateSquareSum ( n ) ) ; } }
Value of the series ( 1 ^ 3 + 2 ^ 3 + 3 ^ 3 + ... + n ^ 3 ) mod 4 for a given n | C # implementation of the approach ; function for obtaining the value of f ( n ) mod 4 ; Find the remainder of n when divided by 4 ; If n is of the form 4 k or 4 k + 3 ; If n is of the form 4 k + 1 or 4 k + 2 ; Driver code
using System ; class GFG { static int fnMod ( int n ) { int rem = n % 4 ; if ( rem == 0 rem == 3 ) return 0 ; else if ( rem == 1 rem == 2 ) return 1 ; return 0 ; } public static void Main ( ) { int n = 6 ; Console . Write ( fnMod ( n ) ) ; } }
Minimum increment operations to make the array in increasing order | C # program to find minimum moves required to make the array in increasing order ; function to find minimum moves required to make the array in increasing order ; to store answer ; iterate over an array ; non - increasing order ; add moves to answer ; increase the element ; return required answer ; Driver code
using System ; class GFG { static int MinimumMoves ( int [ ] a , int n , int x ) { int ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= a [ i - 1 ] ) { int p = ( a [ i - 1 ] - a [ i ] ) / x + 1 ; ans += p ; a [ i ] += p * x ; } } return ans ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 3 , 2 } ; int x = 2 ; int n = arr . Length ; Console . Write ( MinimumMoves ( arr , n , x ) ) ; } }
Check if a large number is divisible by 2 , 3 and 5 or not | C # program to Check if a large number is divisible by 2 , 3 and 5 or not . ; function to return sum of digits of a number ; function to Check if a large number is divisible by 2 , 3 and 5 or not ; Driver code
using System ; class GFG { static int SumOfDigits ( String str , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( int ) ( str [ i ] - '0' ) ; return sum ; } static bool Divisible ( String str , int n ) { if ( SumOfDigits ( str , n ) % 3 == 0 && str [ n - 1 ] == '0' ) return true ; return false ; } public static void Main ( ) { String str = "263730746028908374890" ; int n = str . Length ; if ( Divisible ( str , n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Count all the numbers in a range with smallest factor as K | C # program to find the count of numbers in a range whose smallest factor is K ; Function to check if k is a prime number or not ; Corner case ; Check from 2 to n - 1 ; Function to check if a number is not divisible by any number between 2 and K - 1 ; to check if the num is divisible by any numbers between 2 and k - 1 ; if not divisible by any number between 2 and k - 1 but divisible by k ; Function to find count of numbers in range [ a , b ] with smallest factor as K ; a number can be divisible only by k and not by any number less than k only if k is a prime ; to check if a number has smallest factor as K ; Driver code
using System ; class GFG { static bool isPrime ( int k ) { if ( k <= 1 ) return false ; for ( int i = 2 ; i < k ; i ++ ) if ( k % i == 0 ) return false ; return true ; } static int check ( int num , int k ) { int flag = 1 ; for ( int i = 2 ; i < k ; i ++ ) { if ( num % i == 0 ) flag = 0 ; } if ( flag == 1 ) { if ( num % k == 0 ) return 1 ; else return 0 ; } else return 0 ; } static int findCount ( int a , int b , int k ) { int count = 0 ; if ( ! isPrime ( k ) ) return 0 ; else { int ans ; for ( int i = a ; i <= b ; i ++ ) { ans = check ( i , k ) ; if ( ans == 1 ) count ++ ; else continue ; } } return count ; } public static void Main ( ) { int a = 2020 , b = 6300 , k = 29 ; Console . WriteLine ( findCount ( a , b , k ) ) ; } }
Largest number with the given set of N digits that is divisible by 2 , 3 and 5 | C # implementation of the above approach ; Function to find the largest integer with the given set ; find sum of all the digits look if any 0 is present or not ; if 0 is not present , the resultant number won 't be divisible by 5 ; sort all the elements in a non - decreasing manner ; if there is just one element 0 ; find the remainder of the sum of digits when divided by 3 ; there can a remainder as 1 or 2 ; traverse from the end of the digits ; first element which has the same remainder remove it ; if there is no element which has a same remainder as y ; subtract it by 3 ( could be one or two ) ; delete two minimal digits which has a remainder as y ; print all the digits as a single integer ; Driver code ; initialize the number of set of digits ; initialize all the set of digits in a vector
using System ; using System . Collections ; class GFG { static int findLargest ( int n , ArrayList v ) { int flag = 0 ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( int ) v [ i ] == 0 ) flag = 1 ; sum += ( int ) v [ i ] ; } if ( flag != 1 ) Console . WriteLine ( " Not ▁ possible " ) ; else { v . Sort ( ) ; v . Reverse ( ) ; if ( ( int ) v [ 0 ] == 0 ) { Console . WriteLine ( "0" ) ; return 0 ; } else { int flags = 0 ; int y = ( int ) ( sum % 3 ) ; if ( y != 0 ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( ( int ) v [ i ] % 3 == y ) { v . RemoveAt ( i ) ; flags = 1 ; break ; } } if ( flags == 0 ) { y = 3 - y ; int cnt = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( ( int ) v [ i ] % 3 == y ) { v . RemoveAt ( i ) ; cnt ++ ; if ( cnt >= 2 ) break ; } } } } if ( ( int ) v [ 0 ] == 0 ) Console . WriteLine ( "0" ) ; else for ( int i = 0 ; i < v . Count ; i ++ ) { Console . Write ( v [ i ] ) ; } } } return int . MinValue ; } static void Main ( ) { int [ ] arr = { 3 , 9 , 9 , 6 , 4 , 3 , 6 , 4 , 9 , 6 , 0 } ; int n = 11 ; ArrayList v = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) v . Add ( arr [ i ] ) ; findLargest ( n , v ) ; } }
Find the k | C # program to find the K - th smallest factor ; Function to find the k 'th divisor ; initialize vectors v1 and v2 ; store all the divisors in the two vectors accordingly ; reverse the vector v2 to sort it in increasing order ; if k is greater than the size of vectors then no divisor can be possible ; else print the ( k - 1 ) th value of vector ; If K is lying in first vector ; If K is lying in second vector ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void findkth ( int n , int k ) { List < int > v1 = new List < int > ( ) ; List < int > v2 = new List < int > ( ) ; for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v1 . Add ( i ) ; if ( i != Math . Sqrt ( n ) ) v2 . Add ( n / i ) ; } } v2 . Reverse ( ) ; if ( k > ( v1 . Count + v2 . Count ) ) Console . Write ( " Doesn ' t ▁ Exist " ) ; else { if ( k <= v1 . Count ) Console . Write ( v1 [ k - 1 ] ) ; else Console . Write ( v2 [ k - v1 . Count - 1 ] ) ; } } public static void Main ( String [ ] args ) { int n = 15 , k = 2 ; findkth ( n , k ) ; } }
Number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y are integers | C # implementation of above approach ; function to Find the number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y integers . ; to store answer ; iterate explicitly over all possible values of x ; return answer ; Driver code ; function call
using System ; class GFG { static int NumberOfSolutions ( int a , int b , int c , int d ) { int ans = 0 ; for ( int i = a ; i <= b ; i ++ ) if ( d >= Math . Max ( c , i + 1 ) ) ans += d - Math . Max ( c , i + 1 ) + 1 ; return ans ; } public static void Main ( ) { int a = 2 , b = 3 , c = 3 , d = 4 ; Console . WriteLine ( NumberOfSolutions ( a , b , c , d ) ) ; } }
Minimum value possible of a given function from the given set | C # implementation of above approach ; Function to find the value of F ( n ) ; Driver code
using System ; class GFG { static long findF_N ( long n ) { long ans = 0 ; for ( long i = 0 ; i < n ; ++ i ) ans += ( i + 1 ) * ( n - i - 1 ) ; return ans ; } public static void Main ( ) { long n = 3 ; Console . WriteLine ( findF_N ( n ) ) ; } }
Find N digits number which is divisible by D | C # program to Find N digits number which is divisible by D ; Function to return N digits number which is divisible by D ; to store answer ; Driver code
using System ; class GFG { static string findNumber ( int n , int d ) { string ans = " " ; if ( d != 10 ) { ans += d . ToString ( ) ; for ( int i = 1 ; i < n ; i ++ ) ans += '0' ; } else { if ( n == 1 ) ans += " Impossible " ; else { ans += '1' ; for ( int i = 1 ; i < n ; i ++ ) ans += '0' ; } } return ans ; } public static void Main ( ) { int n = 12 , d = 3 ; Console . WriteLine ( findNumber ( n , d ) ) ; } }
Count all the numbers less than 10 ^ 6 whose minimum prime factor is N | C # implementation of above approach ; the sieve of prime number and count of minimum prime factor ; form the prime sieve ; 1 is not a prime number ; form the sieve ; if i is prime ; if i is the least prime factor ; mark the number j as non prime ; count the numbers whose least prime factor is i ; Driver code ; form the sieve ; display ; display
using System ; class GFG { static int MAX = 1000000 ; static int [ ] sieve_Prime = new int [ MAX + 4 ] ; static int [ ] sieve_count = new int [ MAX + 4 ] ; static void form_sieve ( ) { sieve_Prime [ 1 ] = 1 ; for ( int i = 2 ; i <= MAX ; i ++ ) { if ( sieve_Prime [ i ] == 0 ) { for ( int j = i * 2 ; j <= MAX ; j += i ) { if ( sieve_Prime [ j ] == 0 ) { sieve_Prime [ j ] = 1 ; sieve_count [ i ] ++ ; } } } } } public static void Main ( ) { form_sieve ( ) ; int n = 2 ; Console . WriteLine ( " Count ▁ = ▁ " + ( sieve_count [ n ] + 1 ) ) ; n = 3 ; Console . WriteLine ( " Count ▁ = ▁ " + ( sieve_count [ n ] + 1 ) ) ; } }
How to access elements of a Square Matrix | C # Program to read a square matrix and print the elements on secondary diagonal ; Get the square matrix ; Display the matrix ; Print the elements on secondary diagonal ; check for elements on secondary diagonal
using System ; class GFG { public static void Main ( String [ ] args ) { int [ , ] matrix = new int [ 5 , 5 ] ; int row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index , column_index ] = ++ x ; } } Console . Write ( " The ▁ matrix ▁ is STRNEWLINE " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { Console . Write ( " { 0 } TABSYMBOL " , matrix [ row_index , column_index ] ) ; } Console . Write ( " STRNEWLINE " ) ; } Console . Write ( " on Secondary : " for ( row_index = 0 ; < size ; ++ ) { for ( column_index = 0 ; < size ; ++ ) { if ( ( row_index + column_index ) == size - 1 ) Console . Write ( " { 0 } , ▁ " , matrix [ row_index , column_index ] ) ; } } } }
How to access elements of a Square Matrix | C # Program to read a square matrix and print the elements above secondary diagonal ; Get the square matrix ; Display the matrix ; Print the elements above secondary diagonal ; check for elements above secondary diagonal
using System ; class GFG { public static void Main ( String [ ] args ) { int [ , ] matrix = new int [ 5 , 5 ] ; int row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index , column_index ] = ++ x ; } } Console . Write ( " The ▁ matrix ▁ is STRNEWLINE " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { Console . Write ( " { 0 } TABSYMBOL " , matrix [ row_index , column_index ] ) ; } Console . Write ( " STRNEWLINE " ) ; } Console . Write ( " STRNEWLINE Elements ▁ above ▁ Secondary " + " ▁ diagonal ▁ are : STRNEWLINE " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) < size - 1 ) Console . Write ( " { 0 } , ▁ " , matrix [ row_index , column_index ] ) ; } } } }
How to access elements of a Square Matrix | C # Program to read a square matrix and print the Corner Elements ; Get the square matrix ; Display the matrix ; Print the Corner elements ; check for corner elements
using System ; class GFG { public static void Main ( String [ ] args ) { int [ , ] matrix = new int [ 5 , 5 ] ; int row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index , column_index ] = ++ x ; } } Console . Write ( " The ▁ matrix ▁ is STRNEWLINE " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { Console . Write ( " { 0 } TABSYMBOL " , matrix [ row_index , column_index ] ) ; } Console . Write ( " STRNEWLINE " ) ; } Console . Write ( " STRNEWLINE Corner ▁ Elements ▁ are : STRNEWLINE " ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index == 0 row_index == size - 1 ) && ( column_index == 0 column_index == size - 1 ) ) Console . Write ( " { 0 } , ▁ " , matrix [ row_index , column_index ] ) ; } } } }
Find the largest good number in the divisors of given number N | C # program to find the largest , good number in the divisors of given number N . ; function to return distinct prime factors ; to store distinct prime factors ; run a loop upto sqrt ( n ) ; place this prime factor in vector ; This condition is to handle the case when n is a prime number greater than 1 ; function that returns good number ; distinct prime factors ; to store answer ; product of all distinct prime factors is required answer ; Driver code ; function call
using System ; using System . Collections . Generic ; public class GFG { static List < int > PrimeFactors ( int n ) { List < int > v = new List < int > ( ) ; int x = n ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( x % i == 0 ) { v . Add ( i ) ; while ( x % i == 0 ) x /= i ; } } if ( x > 1 ) v . Add ( x ) ; return v ; } static int GoodNumber ( int n ) { List < int > v = new List < int > ( PrimeFactors ( n ) ) ; int ans = 1 ; for ( int i = 0 ; i < v . Count ; i ++ ) ans *= v [ i ] ; return ans ; } public static void Main ( String [ ] args ) { int n = 12 ; Console . WriteLine ( GoodNumber ( n ) ) ; } }
Find Largest Special Prime which is less than or equal to a given number | C # program to find the Largest Special Prime which is less than or equal to a given number ; Function to check whether the number is a special prime or not ; While number is not equal to zero ; If the number is not prime return false . ; Else remove the last digit by dividing the number by 10. ; If the number has become zero then the number is special prime , hence return true ; Function to find the Largest Special Prime which is less than or equal to a given number ; Initially all numbers are considered Primes . ; There is always an answer possible ; Checking if the number is a special prime or not ; If yes print the number and break the loop . ; Else decrement the number . ; Driver code
using System ; class GFG { static bool checkSpecialPrime ( bool [ ] sieve , int num ) { while ( num != 0 ) { if ( ! sieve [ num ] ) { return false ; } num /= 10 ; } return true ; } static void findSpecialPrime ( int N ) { bool [ ] sieve = new bool [ N + 10 ] ; for ( int i = 0 ; i < N + 10 ; i ++ ) sieve [ i ] = true ; sieve [ 0 ] = sieve [ 1 ] = false ; for ( int i = 2 ; i <= N ; i ++ ) { if ( sieve [ i ] ) { for ( int j = i * i ; j <= N ; j += i ) { sieve [ j ] = false ; } } } while ( true ) { if ( checkSpecialPrime ( sieve , N ) ) { Console . WriteLine ( N ) ; break ; } else N -- ; } } public static void Main ( ) { findSpecialPrime ( 379 ) ; findSpecialPrime ( 100 ) ; } }
Check if an integer can be expressed as a sum of two semi | C # Code to check if an integer can be expressed as sum of two semi - primes ; Utility function to compute semi - primes in a range ; Increment count of prime numbers ; If number is greater than 1 , add it to the count variable as it indicates the number remain is prime number ; if count is equal to '2' then number is semi - prime ; Utility function to check if a number is sum of two semi - primes ; arr [ i ] is already a semi - prime if n - arr [ i ] is also a semi - prime then a number can be expressed as sum of two semi - primes ; Driver code
using System . Collections . Generic ; class GFG { static int MAX = 1000000 ; static List < int > arr = new List < int > ( ) ; static bool [ ] sprime = new bool [ MAX ] ; static void computeSemiPrime ( ) { for ( int i = 0 ; i < MAX ; i ++ ) sprime [ i ] = false ; for ( int i = 2 ; i < MAX ; i ++ ) { int cnt = 0 ; int num = i ; for ( int j = 2 ; cnt < 2 && j * j <= num ; ++ j ) { while ( num % j == 0 ) { num /= j ; ++ cnt ; } } if ( num > 1 ) ++ cnt ; if ( cnt == 2 ) { sprime [ i ] = true ; arr . Add ( i ) ; } } } static bool checkSemiPrime ( int n ) { int i = 0 ; while ( arr [ i ] <= n / 2 ) { if ( sprime [ n - arr [ i ] ] ) { return true ; } i ++ ; } return false ; } public static void Main ( ) { computeSemiPrime ( ) ; int n = 30 ; if ( checkSemiPrime ( n ) ) System . Console . WriteLine ( " YES " ) ; else System . Console . WriteLine ( " NO " ) ; } }
Check if a number is a Pythagorean Prime or not | C # program to check if a number is Pythagorean prime 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 ; Driver Code ; Check if number is prime and of the form 4 n + 1
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 ; } public static void Main ( string [ ] args ) { int n = 13 ; if ( isPrime ( n ) && ( n % 4 == 1 ) ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Divide an isosceles triangle in two parts with ratio of areas as n : m | C # program , to find height h which divide isosceles triangle into ratio n : m ; Function to return the height ; type cast the n , m into float ; calculate the height for cut ; Driver code
using System ; class GFG { static float heightCalculate ( int H , int n , int m ) { float N = ( float ) ( n * 1.0 ) ; float M = ( float ) ( m * 1.0 ) ; float h = H * ( float ) Math . Sqrt ( N / ( N + M ) ) ; return h ; } public static void Main ( ) { int H = 10 , n = 3 , m = 4 ; Console . WriteLine ( heightCalculate ( H , n , m ) ) ; } }