codeparrot/xlcost-text-to-code huggingface dataset:
K 'th Boom Number | C # program to find K 'th Boom number ; This function uses queue data structure to K 'th Boom number ; Create an empty queue of strings ; Enqueue an empty string ; counter for K 'th element ; This loop checks the value of count to become equal to K when value of count will be equals to k we will print the Boom number ; current Boom number ; Store current Boom number before changing it ; Append "2" to string s1 and enqueue it ; Check if count == k ; K 'th Boom number ; Append "3" to string s2 and enqueue it . Note that s2 contains the previous front ; Check if count == k ; K 'th Boom number ; Driver code
using System ; using System . Collections ; class GFG { static void boomNumber ( long k ) { Queue q = new Queue ( ) ; q . Enqueue ( " " ) ; long count = 0 ; while ( count <= k ) { string s1 = ( string ) q . Dequeue ( ) ; string s2 = s1 ; s1 += "2" ; q . Enqueue ( s1 ) ; count ++ ; if ( count == k ) { Console . Write ( s1 ) ; break ; } s2 += "3" ; q . Enqueue ( s2 ) ; count ++ ; if ( count == k ) { Console . Write ( s2 ) ; break ; } } return ; } public static void Main ( string [ ] arg ) { long k = 1000000 ; boomNumber ( k ) ; } }
Check if a number exists having exactly N factors and K prime factors | C # program to check if it is possible to make a number having total N factors and K prime factors ; Function to compute the number of factors of the given number ; Vector to store the prime factors ; While there are no two multiples in the number , divide it by 2 ; If the size is already greater than K , then return true ; Computing the remaining divisors of the number ; If n is divisible by i , then it is a divisor ; If the size is already greater than K , then return true ; If the size is already greater than K , then return true ; If none of the above conditions satisfies , then return false ; Function to check if it is possible to make a number having total N factors and K prime factors ; If total divisors are less than the number of prime divisors , then print No ; Find the number of factors of n ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool factors ( int n , int k ) { List < int > v = new List < int > ( ) ; while ( n % 2 == 0 ) { v . Add ( 2 ) ; n /= 2 ; } if ( v . Count >= k ) return true ; for ( int i = 3 ; i * i <= n ; i += 2 ) { while ( n % i == 0 ) { n = n / i ; v . Add ( i ) ; } if ( v . Count >= k ) return true ; } if ( n > 2 ) v . Add ( n ) ; if ( v . Count >= k ) return true ; return false ; } static void operation ( int n , int k ) { bool answered = false ; if ( n < k ) { answered = true ; Console . WriteLine ( " No " ) ; } bool ok = factors ( n , k ) ; if ( ! ok && ! answered ) { answered = true ; Console . WriteLine ( " No " ) ; } if ( ok && ! answered ) Console . WriteLine ( " Yes " ) ; } public static void Main ( ) { int n = 4 ; int k = 2 ; operation ( n , k ) ; } }
No of Factors of n ! | C # program to count number of factors of n ; Sieve of Eratosthenes to mark all prime number in array prime as 1 ; Initialize all numbers as prime ; Mark composites ; Returns the highest exponent of p in n ! ; Returns the no of factors in n ! ; ans stores the no of factors in n ! ; Find all primes upto n ; Multiply exponent ( of primes ) added with 1 ; if p is a prime then p is also a prime factor of n ! ; Driver code
using System ; class GFG { static void sieve ( int n , int [ ] prime ) { for ( int i = 1 ; i <= n ; i ++ ) prime [ i ] = 1 ; prime [ 1 ] = 0 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == 1 ) { for ( int j = i * i ; j <= n ; j += i ) prime [ j ] = 0 ; } } } static int expFactor ( int n , int p ) { int x = p ; int exponent = 0 ; while ( ( n / x ) > 0 ) { exponent += n / x ; x *= p ; } return exponent ; } static long countFactors ( int n ) { long ans = 1 ; int [ ] prime = new int [ n + 1 ] ; sieve ( n , prime ) ; for ( int p = 1 ; p <= n ; p ++ ) { if ( prime [ p ] == 1 ) ans *= ( expFactor ( n , p ) + 1 ) ; } return ans ; } public static void Main ( ) { int n = 16 ; Console . Write ( " Count ▁ of ▁ factors ▁ of ▁ " + n + " ▁ is ▁ " + countFactors ( n ) ) ; } }
LCM of given array elements |  ; Function to return gcd of a and b ; recursive implementation ; lcm ( a , b ) = ( a * b / gcd ( a , b ) ) ; Driver code
using System ; class GFG { static int __gcd ( int a , int b ) { if ( a == 0 ) return b ; return __gcd ( b % a , a ) ; } static int LcmOfArray ( int [ ] arr , int idx ) { if ( idx == arr . Length - 1 ) { return arr [ idx ] ; } int a = arr [ idx ] ; int b = LcmOfArray ( arr , idx + 1 ) ; return ( a * b / __gcd ( a , b ) ) ; } static void Main ( ) { int [ ] arr = { 1 , 2 , 8 , 3 } ; Console . WriteLine ( LcmOfArray ( arr , 0 ) ) ; int [ ] arr1 = { 2 , 7 , 3 , 9 , 4 } ; Console . WriteLine ( LcmOfArray ( arr1 , 0 ) ) ; } }
Check if a number is a power of another number | C # program to check if a number is power of another number ; Returns true if y is a power of x ; The only power of 1 is 1 itself ; Repeatedly compute power of x ; Check if power of x becomes y ; Driver Code ; check the result for true / false and print .
using System ; class GFG { public static bool isPower ( int x , int y ) { if ( x == 1 ) return ( y == 1 ) ; int pow = 1 ; while ( pow < y ) pow = pow * x ; return ( pow == y ) ; } public static void Main ( ) { Console . WriteLine ( isPower ( 10 , 1 ) ? 1 : 0 ) ; Console . WriteLine ( isPower ( 1 , 20 ) ? 1 : 0 ) ; Console . WriteLine ( isPower ( 2 , 128 ) ? 1 : 0 ) ; Console . WriteLine ( isPower ( 2 , 30 ) ? 1 : 0 ) ; } }
Number of perfect squares between two given numbers | C # program for efficient method to count squares between a & b ; Function to count squares ; Driver Code
using System ; class GFG { static double countSquares ( int a , int b ) { return ( Math . Floor ( Math . Sqrt ( b ) ) - Math . Ceiling ( Math . Sqrt ( a ) ) + 1 ) ; } public static void Main ( ) { int a = 9 , b = 25 ; Console . Write ( " Count ▁ of ▁ squares ▁ is ▁ " + ( int ) countSquares ( a , b ) ) ; } }
Count positive integers with 0 as a digit and maximum ' d ' digits | C # program to find the count of natural numbers upto a given number of digits that contain atleast one zero ; Utility function to calculate the count of natural numbers upto a given number of digits that contain atleast one zero ; Sum of two GP series ; Driver Code
using System ; class GFG { static int findCountUpto ( int d ) { int GP1_Sum = 9 * ( ( int ) ( ( Math . Pow ( 10 , d ) ) - 1 ) / 9 ) ; int GP2_Sum = 9 * ( ( int ) ( ( Math . Pow ( 9 , d ) ) - 1 ) / 8 ) ; return GP1_Sum - GP2_Sum ; } public static void Main ( ) { int d = 1 ; Console . WriteLine ( findCountUpto ( d ) ) ; d = 2 ; Console . WriteLine ( findCountUpto ( d ) ) ; d = 4 ; Console . WriteLine ( findCountUpto ( d ) ) ; } }
Check if count of divisors is even or odd | C # program using Naive Solution to find if count of divisors is even or odd ; Function to count the divisors ; Initialize count of divisors ; Note that this loop runs till square root ; If divisors are equal increment count by one Otherwise increment count by 2 ; Driver code
using System ; class GFG { static void countDivisors ( int n ) { int count = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( n ) + 1 ; i ++ ) { if ( n % i == 0 ) count += ( n / i == i ) ? 1 : 2 ; } if ( count % 2 == 0 ) Console . Write ( " Even " ) ; else Console . Write ( " Odd " ) ; } public static void Main ( ) { Console . Write ( " The ▁ count ▁ of ▁ divisor : ▁ " ) ; countDivisors ( 10 ) ; } }
Gray to Binary and Binary to Gray conversion | C # program for above approach ; Driver Code
using System ; class GFG { static int greyConverter ( int n ) { return n ^ ( n >> 1 ) ; } public static void Main ( string [ ] args ) { int n = 3 ; Console . WriteLine ( greyConverter ( n ) ) ; n = 9 ; Console . WriteLine ( greyConverter ( n ) ) ; } }
Compute n ! under modulo p | C # program Returns n % p using Sieve of Eratosthenes ; Returns largest power of p that divides n ! ; Initialize result ; Calculate x = n / p + n / ( p ^ 2 ) + n / ( p ^ 3 ) + ... . ; Utility function to do modular exponentiation . It returns ( x ^ y ) % p ; Initialize result 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 ; Returns n ! % p ; Use Sieve of Eratosthenes to find all primes smaller than n ; Consider all primes found by Sieve ; Find the largest power of prime ' i ' that divides n ; Multiply result with ( i ^ k ) % p ; Driver method
using System ; public class GFG { static int largestPower ( int n , int p ) { int x = 0 ; while ( n > 0 ) { n /= p ; x += n ; } return x ; } static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) { res = ( res * x ) % p ; } x = ( x * x ) % p ; } return res ; } static int modFact ( int n , int p ) { if ( n >= p ) { return 0 ; } int res = 1 ; bool [ ] isPrime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) isPrime [ i ] = true ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( isPrime [ i ] ) { for ( int j = 2 * i ; j <= n ; j += i ) { isPrime [ j ] = false ; } } } for ( int i = 2 ; i <= n ; i ++ ) { if ( isPrime [ i ] ) { int k = largestPower ( n , i ) ; res = ( res * power ( i , k , p ) ) % p ; } } return res ; } static public void Main ( ) { int n = 25 , p = 29 ; Console . WriteLine ( modFact ( n , p ) ) ; } }
Count number of squares in a rectangle | C # program to count squares in a rectangle of size m x n ; Returns count of all squares in a rectangle of size m x n ; If n is smaller , swap m and n ; Now n is greater dimension , apply formula ; Driver method
using System ; class GFG { static int countSquares ( int m , int n ) { if ( n < m ) { int temp = m ; m = n ; n = temp ; } return m * ( m + 1 ) * ( 2 * m + 1 ) / 6 + ( n - m ) * m * ( m + 1 ) / 2 ; } public static void Main ( ) { int m = 4 , n = 3 ; Console . WriteLine ( " Count ▁ of ▁ squares ▁ is ▁ " + countSquares ( m , n ) ) ; } }
Sum of bit differences among all pairs | package whatever do not write package name here ; int diff = 0 ; hold the ans ; XOR toggles the bits and will form a number that will have set bits at the places where the numbers bits differ eg : 010 ^ 111 = 101. . . diff of bits = count of 1 's = 2 ; when i == j ( same numbers ) the xor would be 0 , thus our ans will remain unaffected as ( 2 * 0 = 0 ) ; Kernighan algo ; int count = 0 ; ` count ` stores the total bits set in ` n ` ; n = n & ( n - 1 ) ; clear the least significant bit set
using System ; public class GFG { static int sumBitDiff ( int [ ] arr ) { for ( int i = 0 ; i < arr . Length ; i ++ ) { for ( int j = i ; j < arr . Length ; j ++ ) { int xor = arr [ i ] ^ arr [ j ] ; diff += 2 * count ; } } return diff ; } static int countSetBits ( int n ) { while ( n != 0 ) { count ++ ; } return count ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 10 } ; int ans = sumBitDiff ( arr ) ; Console . WriteLine ( ans ) ; } }
Add two numbers using ++ and / or | C # program to add two numbers using ++ ; Returns value of x + y without using + ; If y is positive , y times add 1 to x ; If y is negative , y times subtract 1 from x ; Driver code
using System ; public class GFG { static int add ( int x , int y ) { while ( y > 0 && y != 0 ) { x ++ ; y -- ; } while ( y < 0 && y != 0 ) { x -- ; y ++ ; } return x ; } public static void Main ( ) { Console . WriteLine ( add ( 43 , 23 ) ) ; Console . WriteLine ( add ( 43 , - 23 ) ) ; } }
Count factorial numbers in a given range | C # Program to count factorial numbers in given range ; Function to count factorial ; Find the first factorial number numbers ' fact ' greater than or equal to ' low ' ; Count factorial numbers in range [ low , high ] ; Return the count ; Driver code
using System ; public class GFG { static int countFact ( int low , int high ) { int fact = 1 , x = 1 ; while ( fact < low ) { fact = fact * x ; x ++ ; } int res = 0 ; while ( fact <= high ) { res ++ ; fact = fact * x ; x ++ ; } return res ; } public static void Main ( ) { Console . Write ( " Count ▁ is ▁ " + countFact ( 2 , 720 ) ) ; } }
Find number of days between two given dates | C # program two find number of days between two given dates ; A date has day ' d ' , month ' m ' and year ' y ' ; To store number of days in all months from January to Dec . ; This function counts number of leap years before the given date ; Check if the current year needs to be considered for the count of leap years or not ; An year is a leap year if it is a multiple of 4 , multiple of 400 and not a multiple of 100. ; This function returns number of days between two given dates ; initialize count using years and day ; Add days for months in given date ; Since every leap year is of 366 days , Add a day for every leap year ; SIMILARLY , COUNT TOTAL NUMBER OF DAYS BEFORE ' dt2' ; return difference between two counts ; Driver code ; Function call
using System ; class GFG { public class Date { public int d , m , y ; public Date ( int d , int m , int y ) { this . d = d ; this . m = m ; this . y = y ; } } ; static int [ ] monthDays = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; static int countLeapYears ( Date d ) { int years = d . y ; if ( d . m <= 2 ) { years -- ; } return years / 4 - years / 100 + years / 400 ; } static int getDifference ( Date dt1 , Date dt2 ) { int n1 = dt1 . y * 365 + dt1 . d ; for ( int i = 0 ; i < dt1 . m - 1 ; i ++ ) { n1 += monthDays [ i ] ; } n1 += countLeapYears ( dt1 ) ; int n2 = dt2 . y * 365 + dt2 . d ; for ( int i = 0 ; i < dt2 . m - 1 ; i ++ ) { n2 += monthDays [ i ] ; } n2 += countLeapYears ( dt2 ) ; return ( n2 - n1 ) ; } public static void Main ( String [ ] args ) { Date dt1 = new Date ( 1 , 2 , 2000 ) ; Date dt2 = new Date ( 1 , 2 , 2004 ) ; Console . WriteLine ( " Difference ▁ between ▁ two ▁ dates ▁ is ▁ " + getDifference ( dt1 , dt2 ) ) ; } }
Find length of period in decimal value of 1 / n | C # program to find length of period of 1 / n without using map or hash ; Function to find length of period in 1 / n ; Find the ( n + 1 ) th remainder after decimal point in value of 1 / n ; Store ( n + 1 ) th remainder ; Count the number of remainders before next occurrence of ( n + 1 ) ' th ▁ remainder ▁ ' d ' ; Driver code
using System ; class GFG { static int getPeriod ( int n ) { int rem = 1 ; for ( int i = 1 ; i <= n + 1 ; i ++ ) rem = ( 10 * rem ) % n ; int d = rem ; int count = 0 ; do { rem = ( 10 * rem ) % n ; count ++ ; } while ( rem != d ) ; return count ; } public static void Main ( ) { Console . Write ( getPeriod ( 3 ) + " STRNEWLINE " ) ; Console . Write ( getPeriod ( 7 ) ) ; } }
Replace all â €˜ 0 â €™ with â €˜ 5 â €™ in an input Integer |  ; Returns the number to be added to the input to replace all zeroes with five ; Amount to be added ; Unit decimal place ; A number divisible by 10 , then this is a zero occurrence in the input ; Move one decimal place ; Driver Code
using System ; class GFG { static int replace0with5 ( int number ) { return number += calculateAddedValue ( number ) ; } static int calculateAddedValue ( int number ) { int result = 0 ; int decimalPlace = 1 ; if ( number == 0 ) { result += ( 5 * decimalPlace ) ; } while ( number > 0 ) { if ( number % 10 == 0 ) result += ( 5 * decimalPlace ) ; number /= 10 ; decimalPlace *= 10 ; } return result ; } static public void Main ( ) { Console . WriteLine ( replace0with5 ( 1020 ) ) ; } }
Program to find remainder without using modulo or % operator | C # program to find remainder without using modulo operator ; This function returns remainder of num / divisor without using % ( modulo ) operator ; Driver program to test above functions
using System ; class GFG { static int getRemainder ( int num , int divisor ) { return ( num - divisor * ( num / divisor ) ) ; } public static void Main ( ) { Console . Write ( getRemainder ( 100 , 7 ) ) ; } }
Efficient Program to Compute Sum of Series 1 / 1 ! + 1 / 2 ! + 1 / 3 ! + 1 / 4 ! + . . + 1 / n ! | A simple C # program to compute sum of series 1 / 1 ! + 1 / 2 ! + . . + 1 / n ! ; An Efficient Function to return value of 1 / 1 ! + 1 / 2 ! + . . + 1 / n ! ; Update factorial ; Update series sum ; Driver program
using System ; class GFG { static double sum ( int n ) { double sum = 0 ; int fact = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { fact *= i ; sum += 1.0 / fact ; } return sum ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( sum ( n ) ) ; } }
Print first k digits of 1 / n where n is a positive integer | C # code to Print first k digits of 1 / n where n is a positive integer ; Function to print first k digits after dot in value of 1 / n . n is assumed to be a positive integer . ; Initialize remainder ; Run a loop k times to print k digits ; The next digit can always be obtained as doing ( 10 * rem ) / 10 ; Update remainder ; Driver program
using System ; class GFG { static void print ( int n , int k ) { int rem = 1 ; for ( int i = 0 ; i < k ; i ++ ) { Console . Write ( ( 10 * rem ) / n ) ; rem = ( 10 * rem ) % n ; } } public static void Main ( ) { int n = 7 , k = 3 ; print ( n , k ) ; Console . WriteLine ( ) ; n = 21 ; k = 4 ; print ( n , k ) ; } }
Program to find sum of series 1 + 1 / 2 + 1 / 3 + 1 / 4 + . . + 1 / n | C # Program to find sum of series ; Function to return sum of 1 / 1 + 1 / 2 + 1 / 3 + . . + 1 / n ; Driven Program
using System ; class GFG { static float sum ( int n ) { double i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return ( float ) s ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( " Sum ▁ is ▁ " + sum ( n ) ) ; } }
Program to find GCD or HCF of two numbers | C # program to find GCD of two numbers ; Recursive function to return gcd of a and b ; Driver method
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static void Main ( ) { int a = 98 , b = 56 ; Console . WriteLine ( " GCD ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + gcd ( a , b ) ) ; } }
Rearrange an array so that arr [ i ] becomes arr [ arr [ i ] ] with O ( 1 ) extra space | C # Program to rearrange an array so that arr [ i ] becomes arr [ arr [ i ] ] with O ( 1 ) extra space ; Function to rearrange an array in - place so that arr [ i ] becomes arr [ arr [ i ] ] . ; First step : Increase all values by ( arr [ arr [ i ] ] % n ) * n ; Second Step : Divide all values by n ; A utility function to print an array of size n ; Driver Code
using System ; class Rearrange { void rearrange ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) arr [ i ] += ( arr [ arr [ i ] ] % n ) * n ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] /= n ; } void printArr ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( " " ) ; } public static void Main ( ) { Rearrange rearrange = new Rearrange ( ) ; int [ ] arr = { 3 , 2 , 0 , 1 } ; int n = arr . Length ; Console . Write ( " Given ▁ Array ▁ is ▁ : " ) ; rearrange . printArr ( arr , n ) ; rearrange . rearrange ( arr , n ) ; Console . Write ( " Modified ▁ Array ▁ is ▁ : " ) ; rearrange . printArr ( arr , n ) ; } }
Print all sequences of given length | C # program of above approach ; A utility function that prints a given arr [ ] of length size ; The core function that recursively generates and prints all sequences of length k ; A function that uses printSequencesRecur ( ) to prints all sequences from 1 , 1 , . .1 to n , n , . . n ; Driver Code
using System ; class GFG { static void printArray ( int [ ] arr , int size ) { for ( int i = 0 ; i < size ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; return ; } static void printSequencesRecur ( int [ ] arr , int n , int k , int index ) { int i ; if ( k == 0 ) { printArray ( arr , index ) ; } if ( k > 0 ) { for ( i = 1 ; i <= n ; ++ i ) { arr [ index ] = i ; printSequencesRecur ( arr , n , k - 1 , index + 1 ) ; } } } static void printSequences ( int n , int k ) { int [ ] arr = new int [ k ] ; printSequencesRecur ( arr , n , k , 0 ) ; return ; } public static void Main ( ) { int n = 3 ; int k = 2 ; printSequences ( n , k ) ; } }
Check if a number is multiple of 5 without using / and % operators | C # code to check if a number is multiple of 5 without using / and % operators ; assumes that n is a positive integer ; Driver Code
using System ; class GFG { static bool isMultipleof5 ( int n ) { while ( n > 0 ) n = n - 5 ; if ( n == 0 ) return true ; return false ; } public static void Main ( ) { int n = 19 ; if ( isMultipleof5 ( n ) == true ) Console . Write ( n + " ▁ is ▁ multiple ▁ of ▁ 5 STRNEWLINE " ) ; else Console . Write ( n + " ▁ is ▁ not ▁ a ▁ multiple ▁ of ▁ 5 STRNEWLINE " ) ; } }
Count pairs from an array having sum of twice of their AND and XOR equal to K | C # program for the above approach ; Function to count number of pairs satisfying the given conditions ; Stores the frequency of array elements ; Stores the total number of pairs ; Traverse the array ; Add it to cnt ; Update frequency of current array element ; Print the count ; Driver Code ; Given array ; Size of the array ; Given value of K
using System ; using System . Collections . Generic ; public class GFG { static void countPairs ( int [ ] arr , int N , int K ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . ContainsKey ( K - arr [ i ] ) ) cnt += mp [ K - arr [ i ] ] ; if ( mp . ContainsKey ( arr [ i ] ) ) { var val = mp [ arr [ i ] ] ; mp . Remove ( arr [ i ] ) ; mp . Add ( arr [ i ] , val + 1 ) ; } else { mp . Add ( arr [ i ] , 1 ) ; } } Console . WriteLine ( cnt ) ; } static public void Main ( ) { int [ ] arr = { 1 , 5 , 4 , 8 , 7 } ; int N = arr . Length ; int K = 9 ; countPairs ( arr , N , K ) ; } }
Queries to count array elements from a given range having a single set bit | C # program for the above approach ; Function to check whether only one bit is set or not ; Function to perform Range - query ; Function to count array elements with a single set bit for each range in a query ; Initialize array for Prefix sum ; Driver code ; Given array ; Size of the array ; Given queries ; Size of queries array
using System ; using System . Collections . Generic ; class GFG { static int check ( int x ) { if ( ( ( x ) & ( x - 1 ) ) == 0 ) return 1 ; return 0 ; } static int query ( int l , int r , int [ ] pre ) { if ( l == 0 ) return pre [ r ] ; else return pre [ r ] - pre [ l - 1 ] ; } static void countInRange ( int [ ] arr , int N , List < Tuple < int , int > > queries , int Q ) { int [ ] pre = new int [ N ] ; pre [ 0 ] = check ( arr [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { pre [ i ] = pre [ i - 1 ] + check ( arr [ i ] ) ; } int c = 0 ; int q = 0 ; while ( q < Q ) { int l = queries [ q ] . Item1 ; int r = queries [ q ] . Item2 ; c ++ ; q ++ ; Console . Write ( query ( l , r , pre ) + " ▁ " ) ; } } static void Main ( ) { int [ ] arr = { 12 , 11 , 16 , 8 , 2 , 5 , 1 , 3 , 256 , 1 } ; int N = arr . Length ; List < Tuple < int , int > > queries = new List < Tuple < int , int > > ( ) ; queries . Add ( new Tuple < int , int > ( 0 , 9 ) ) ; queries . Add ( new Tuple < int , int > ( 4 , 9 ) ) ; int Q = queries . Count ; countInRange ( arr , N , queries , Q ) ; } }