codeparrot/xlcost-text-to-code huggingface dataset:
Doolittle Algorithm : LU Decomposition | C ++ Program to decompose a matrix into lower and upper triangular matrix ; Decomposing matrix into Upper and Lower triangular matrix ; Upper Triangular ; Summation of L ( i , j ) * U ( j , k ) ; Evaluating U ( i , k ) ; Lower Triangular ; lower [ i ] [ i ] = 1 ; Diagonal as 1 ; Summation of L ( k , j ) * U ( j , i ) ; Evaluating L ( k , i ) ; setw is for displaying nicely ; Displaying the result : ; Lower ; Upper ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MAX = 100 ; void luDecomposition ( int mat [ ] [ MAX ] , int n ) { int lower [ n ] [ n ] , upper [ n ] [ n ] ; memset ( lower , 0 , sizeof ( lower ) ) ; memset ( upper , 0 , sizeof ( upper ) ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int k = i ; k < n ; k ++ ) { int sum = 0 ; for ( int j = 0 ; j < i ; j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ; upper [ i ] [ k ] = mat [ i ] [ k ] - sum ; } for ( int k = i ; k < n ; k ++ ) { if ( i == k ) else { int sum = 0 ; for ( int j = 0 ; j < i ; j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ; lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ; } } } cout << setw ( 6 ) << " TABSYMBOL Lower ▁ Triangular " << setw ( 32 ) << " Upper ▁ Triangular " << endl ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) cout << setw ( 6 ) << lower [ i ] [ j ] << " TABSYMBOL " ; cout << " TABSYMBOL " ; for ( int j = 0 ; j < n ; j ++ ) cout << setw ( 6 ) << upper [ i ] [ j ] << " TABSYMBOL " ; cout << endl ; } } int main ( ) { int mat [ ] [ MAX ] = { { 2 , -1 , -2 } , { -4 , 6 , 3 } , { -4 , -2 , 8 } } ; luDecomposition ( mat , 3 ) ; return 0 ; }
Divide number into two parts divisible by given numbers | C ++ code to break the number string into two divisible parts by given numbers ; method prints divisible parts if possible , otherwise prints ' Not ▁ possible ' ; creating arrays to store reminder ; looping over all suffix and storing reminder with f ; getting suffix reminder from previous suffix reminder ; looping over all prefix and storing reminder with s ; getting prefix reminder from next prefix reminder ; updating base value ; now looping over all reminders to check partition condition ; if both reminders are 0 and digit itself is not 0 , then print result and return ; if we reach here , then string can ' be  partitioned under constraints ; Driver code to test above methods
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printTwoDivisibleParts ( string num , int f , int s ) { int N = num . length ( ) ; int prefixReminder [ N + 1 ] ; int suffixReminder [ N + 1 ] ; suffixReminder [ 0 ] = 0 ; for ( int i = 1 ; i < N ; i ++ ) suffixReminder [ i ] = ( suffixReminder [ i - 1 ] * 10 + ( num [ i - 1 ] - '0' ) ) % f ; prefixReminder [ N ] = 0 ; int base = 1 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { prefixReminder [ i ] = ( prefixReminder [ i + 1 ] + ( num [ i ] - '0' ) * base ) % s ; base = ( base * 10 ) % s ; } for ( int i = 0 ; i < N ; i ++ ) { if ( prefixReminder [ i ] == 0 && suffixReminder [ i ] == 0 && num [ i ] != '0' ) { cout << num . substr ( 0 , i ) << " ▁ " << num . substr ( i ) << endl ; return ; } } cout << " Not ▁ Possible STRNEWLINE " ; } int main ( ) { string num = "246904096" ; int f = 12345 ; int s = 1024 ; printTwoDivisibleParts ( num , f , s ) ; return 0 ; }
Number of subarrays whose minimum and maximum are same | CPP program to count number of subarrays having same minimum and maximum . ; calculate the no of contiguous subarrays which has same minimum and maximum ; stores the answer ; loop to traverse from 0 - n ; start checking subarray from next element ; traverse for finding subarrays ; if the elements are same then we check further and keep a count of same numbers in ' r ' ; the no of elements in between r and i with same elements . ; the no of subarrays that can be formed between i and r ; again start checking from the next index ; returns answer ; drive program to test the above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculate ( int a [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int r = i + 1 ; for ( int j = r ; j < n ; j ++ ) { if ( a [ i ] == a [ j ] ) r += 1 ; else break ; } int d = r - i ; ans += ( d * ( d + 1 ) / 2 ) ; i = r - 1 ; } return ans ; } int main ( ) { int a [ ] = { 2 , 4 , 5 , 3 , 3 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << calculate ( a , n ) ; return 0 ; }
Count of numbers satisfying m + sum ( m ) + sum ( sum ( m ) ) = N | CPP program to count numbers satisfying equation . ; function that returns sum of digits in a number ; initially sum of digits is 0 ; loop runs till all digits have been extracted ; last digit from backside ; sums up the digits ; the number is reduced to the number removing the last digit ; returns the sum of digits in a number ; function to calculate the count of such occurrences ; counter to calculate the occurrences ; loop to traverse from n - 97 to n ; calls the function to calculate the sum of digits of i ; calls the function to calculate the sum of digits of a ; if the summation is equal to n then increase counter by 1 ; returns the count ; driver program to test the above function ; calls the function to get the answer
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sum ( int n ) { int rem = 0 ; int sum_of_digits = 0 ; while ( n > 0 ) { rem = n % 10 ; sum_of_digits += rem ; n = n / 10 ; } return sum_of_digits ; } int count ( int n ) { int c = 0 ; for ( int i = n - 97 ; i <= n ; i ++ ) { int a = sum ( i ) ; int b = sum ( a ) ; if ( ( i + a + b ) == n ) { c += 1 ; } } return c ; } int main ( ) { int n = 9939 ; cout << count ( n ) << endl ; return 0 ; }
Check if a number is power of k using base changing method | CPP program to check if a number can be raised to k ; loop to change base n to base = k ; Find current digit in base k ; If digit is neither 0 nor 1 ; Make sure that only one 1 is present . ; Driver code
#include <iostream> NEW_LINE #include <algorithm> NEW_LINE using namespace std ; bool isPowerOfK ( unsigned int n , unsigned int k ) { bool oneSeen = false ; while ( n > 0 ) { int digit = n % k ; if ( digit > 1 ) return false ; if ( digit == 1 ) { if ( oneSeen ) return false ; oneSeen = true ; } n /= k ; } return true ; } int main ( ) { int n = 64 , k = 4 ; if ( isPowerOfK ( n , k ) ) cout << " Yes " ; else cout << " No " ; }
Check if number is palindrome or not in Octal | C ++ program to check if octal representation of a number is prime ; Function to Check no is in octal or not ; Function To check no is palindrome or not ; If number is already in octal , we traverse digits using repeated division with 10. Else we traverse digits using repeated division with 8 ; To store individual digits ; Traversing all digits ; checking if octal no is palindrome ; Driver code
#include <iostream> NEW_LINE using namespace std ; const int MAX_DIGITS = 20 ; bool isOctal ( long n ) { while ( n ) { if ( ( n % 10 ) >= 8 ) return false ; else n = n / 10 ; } return true ; } int isPalindrome ( long n ) { int divide = ( isOctal ( n ) == false ) ? 8 : 10 ; int octal [ MAX_DIGITS ] ; int i = 0 ; while ( n != 0 ) { octal [ i ++ ] = n % divide ; n = n / divide ; } for ( int j = i - 1 , k = 0 ; k <= j ; j -- , k ++ ) if ( octal [ j ] != octal [ k ] ) return false ; return true ; } int main ( ) { long n = 97 ; if ( isPalindrome ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Find all factorial numbers less than or equal to n | CPP program to find all factorial numbers smaller than or equal to n . ; Compute next factorial using previous ; Driver code
#include <iostream> NEW_LINE using namespace std ; void printFactorialNums ( int n ) { int fact = 1 ; int x = 2 ; while ( fact <= n ) { cout << fact << " ▁ " ; fact = fact * x ; x ++ ; } } int main ( ) { int n = 100 ; printFactorialNums ( n ) ; return 0 ; }
Happy Numbers | CPP program to check if a number is happy number ; Returns sum of squares of digits of a number n . For example for n = 12 it returns 1 + 4 = 5 ; Returns true if n is Happy number else returns false . ; A set to store numbers during repeated square sum process ; Keep replacing n with sum of squares of digits until we either reach 1 or we endup in a cycle ; Number is Happy if we reach 1 ; Replace n with sum of squares of digits ; If n is already visited , a cycle is formed , means not Happy ; Mark n as visited ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sumDigitSquare ( int n ) { int sq = 0 ; while ( n ) { int digit = n % 10 ; sq += digit * digit ; n = n / 10 ; } return sq ; } bool isHappy ( int n ) { set < int > s ; s . insert ( n ) ; while ( 1 ) { if ( n == 1 ) return true ; n = sumDigitSquare ( n ) ; if ( s . find ( n ) != s . end ( ) ) return false ; s . insert ( n ) ; } return false ; } int main ( ) { int n = 23 ; if ( isHappy ( n ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }
Check whether a number has exactly three distinct factors or not | C ++ program to check whether number has exactly three distinct factors or not ; Utility function to check whether 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 whether given number has three distinct factors or not ; Find square root of number ; Check whether number is perfect square or not ; If number is perfect square , check whether square root is prime or not ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; 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 ; } bool isThreeDisctFactors ( long long n ) { int sq = ( int ) sqrt ( n ) ; if ( 1LL * sq * sq != n ) return false ; return isPrime ( sq ) ? true : false ; } int main ( ) { long long num = 9 ; if ( isThreeDisctFactors ( num ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; num = 15 ; if ( isThreeDisctFactors ( num ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; num = 12397923568441 ; if ( isThreeDisctFactors ( num ) ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; return 0 ; }
Find the last digit when factorial of A divides factorial of B | CPP program to find last digit of a number obtained by dividing factorial of a number with factorial of another number . ; Function which computes the last digit of resultant of B ! / A ! ; if ( A == B ) If A = B , B ! = A ! and B ! / A ! = 1 ; If difference ( B - A ) >= 5 , answer = 0 ; If non of the conditions are true , we iterate from A + 1 to B and multiply them . We are only concerned for the last digit , thus we take modulus of 10 ; driver function
#include <iostream> NEW_LINE using namespace std ; int computeLastDigit ( long long int A , long long int B ) { int variable = 1 ; return 1 ; else if ( ( B - A ) >= 5 ) return 0 ; else { for ( long long int i = A + 1 ; i <= B ; i ++ ) variable = ( variable * ( i % 10 ) ) ; return variable % 10 ; } } int main ( ) { cout << computeLastDigit ( 2632 , 2634 ) ; return 0 ; }
Program for sum of arithmetic series | CPP Program to find the sum of arithmetic series . ; Function to find sum of series . ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; float sumOfAP ( float a , float d , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + a ; a = a + d ; } return sum ; } int main ( ) { int n = 20 ; float a = 2.5 , d = 1.5 ; cout << sumOfAP ( a , d , n ) ; return 0 ; }
Product of factors of number | C ++ program to calculate product of factors of number ; function to product the factors ; If factors are equal , multiply only once ; Otherwise multiply both ; Driver code
#include <bits/stdc++.h> NEW_LINE #define M  1000000007 NEW_LINE using namespace std ; long long multiplyFactors ( int n ) { long long prod = 1 ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) prod = ( prod * i ) % M ; else { prod = ( prod * i ) % M ; prod = ( prod * n / i ) % M ; } } } return prod ; } int main ( ) { int n = 12 ; cout << multiplyFactors ( n ) << endl ; return 0 ; }
Product of factors of number | C ++ program to calculate product of factors of number ; Iterative Function to calculate ( x ^ y ) in O ( log y ) ; function to count the factors ; If factors are equal , count only once ; Otherwise count both ; Calculate product of factors ; If numFactor is odd return power ( n , numFactor / 2 ) * sqrt ( n ) ; Driver code
#include <bits/stdc++.h> NEW_LINE #define M  1000000007 NEW_LINE using namespace std ; long long power ( long long x , long long y ) { long long res = 1 ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % M ; y = ( y >> 1 ) % M ; x = ( x * x ) % M ; } return res ; } int countFactors ( int n ) { int count = 0 ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) count ++ ; else count += 2 ; } } return count ; } long long multiplyFactors ( int n ) { int numFactor = countFactors ( n ) ; long long product = power ( n , numFactor / 2 ) ; if ( numFactor & 1 ) product = ( product * ( int ) sqrt ( n ) ) % M ; return product ; } int main ( ) { int n = 12 ; cout << multiplyFactors ( n ) << endl ; return 0 ; }
Decimal representation of given binary string is divisible by 10 or not | C ++ implementation to check whether decimal representation of given binary number is divisible by 10 or not ; function to check whether decimal representation of given binary number is divisible by 10 or not ; if last digit is '1' , then number is not divisible by 10 ; to accumulate the sum of last digits in perfect powers of 2 ; traverse from the 2 nd last up to 1 st digit in ' bin ' ; if digit in '1' ; calculate digit 's position from  the right ; according to the digit 's position,  obtain the last digit of the applicable  perfect power of 2 ; if last digit is 0 , then divisible by 10 ; not divisible by 10 ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDivisibleBy10 ( string bin ) { int n = bin . size ( ) ; if ( bin [ n - 1 ] == '1' ) return false ; int sum = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( bin [ i ] == '1' ) { int posFromRight = n - i - 1 ; if ( posFromRight % 4 == 1 ) sum = sum + 2 ; else if ( posFromRight % 4 == 2 ) sum = sum + 4 ; else if ( posFromRight % 4 == 3 ) sum = sum + 8 ; else if ( posFromRight % 4 == 0 ) sum = sum + 6 ; } } if ( sum % 10 == 0 ) return true ; return false ; } int main ( ) { string bin = "11000111001110" ; if ( isDivisibleBy10 ( bin ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Tribonacci Numbers | A space optimized based CPP program to print first n Tribonacci numbers . ; Initialize first three numbers ; Loop to add previous three numbers for each number starting from 3 and then assign first , second , third to second , third , and curr to third respectively ; Driver code
#include <iostream> NEW_LINE using namespace std ; void printTrib ( int n ) { if ( n < 1 ) return ; int first = 0 , second = 0 ; int third = 1 ; cout << first << " ▁ " ; if ( n > 1 ) cout << second << " ▁ " ; if ( n > 2 ) cout << second << " ▁ " ; for ( int i = 3 ; i < n ; i ++ ) { int curr = first + second + third ; first = second ; second = third ; third = curr ; cout << curr << " ▁ " ; } } int main ( ) { int n = 10 ; printTrib ( n ) ; return 0 ; }
Prime Number of Set Bits in Binary Representation | Set 2 | C ++ code to find count of numbers having prime number of set bits in their binary representation in the range [ L , R ] ; Function to create an array of prime numbers upto number ' n ' ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as false . A value in prime [ i ] will finally be true if i is Not a prime , else false . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Append all the prime numbers to the list ; Utility function to count the number of set bits ; Driver code ; Here prime numbers are checked till the maximum number of bits possible because that the maximum bit sum possible is the number of bits itself .
#include <bits/stdc++.h> NEW_LINE using namespace std ; #include <cmath> NEW_LINE vector < int > SieveOfEratosthenes ( int n ) { bool prime [ n + 1 ] ; memset ( prime , false , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == false ) for ( int i = p * 2 ; i < n + 1 ; i += p ) prime [ i ] = true ; } vector < int > lis ; for ( int p = 2 ; p <= n ; p ++ ) if ( prime [ p ] == false ) lis . push_back ( p ) ; return lis ; } int setBits ( int n ) { return __builtin_popcount ( n ) ; } int main ( ) { int x = 4 , y = 8 ; int count = 0 ; vector < int > primeArr = SieveOfEratosthenes ( ceil ( log2 ( y ) ) ) ; for ( int i = x ; i < y + 1 ; i ++ ) { int temp = setBits ( i ) ; for ( int j = 0 ; j < primeArr . size ( ) ; j ++ ) { if ( temp == primeArr [ j ] ) { count += 1 ; break ; } } } cout << count << endl ; return 0 ; }
Count trailing zeroes present in binary representation of a given number using XOR | C ++ implementation of the above approach ; Function to print count of trailing zeroes present in binary representation of N ; Count set bits in ( N ^ ( N - 1 ) ) ; If res < 0 , return 0 ; Driver Code ; Function call to print the count of trailing zeroes in the binary representation of N
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countTrailingZeroes ( int N ) { int res = log2 ( N ^ ( N - 1 ) ) ; return res >= 0 ? res : 0 ; } int main ( ) { int N = 12 ; cout << countTrailingZeroes ( N ) ; return 0 ; }
Maximum sum of Bitwise XOR of elements with their respective positions in a permutation of size N | C ++ program for the above approach ; Function to calculate the score ; Stores the possible score for the current permutation ; Traverse the permutation array ; Return the final score ; Function to generate all the possible permutation and get the max score ; If arr [ ] length is equal to N process the permutation ; Generating the permutations ; If the current element is chosen ; Mark the current element as true ; Recursively call for next possible permutation ; Backtracking ; Return the ans ; Driver Code ; Stores the permutation ; To display the result
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calcScr ( vector < int > arr ) { int ans = 0 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) ans += ( i ^ arr [ i ] ) ; return ans ; } int getMax ( vector < int > arr , int ans , vector < bool > chosen , int N ) { if ( arr . size ( ) == N ) { ans = max ( ans , calcScr ( arr ) ) ; return ans ; } for ( int i = 0 ; i < N ; i ++ ) { if ( chosen [ i ] ) continue ; chosen [ i ] = true ; arr . push_back ( i ) ; ans = getMax ( arr , ans , chosen , N ) ; chosen [ i ] = false ; arr . pop_back ( ) ; } return ans ; } int main ( ) { int N = 2 ; vector < int > arr ; int ans = -1 ; vector < bool > chosen ( N , false ) ; ans = getMax ( arr , ans , chosen , N ) ; cout << ans << endl ; }
Additive Congruence method for generating Pseudo Random Numbers | C ++ implementation of the above approach ; Function to generate random numbers ; Initialize the seed state ; Traverse to generate required numbers of random numbers ; Follow the additive congruential method ; Driver Code ; seed value ; modulus parameter ; increment term ; Number of Random numbers to be generated ; To store random numbers ; Function Call ; Print the generated random numbers
#include <bits/stdc++.h> NEW_LINE using namespace std ; void additiveCongruentialMethod ( int Xo , int m , int c , vector < int > & randomNums , int noOfRandomNums ) { randomNums [ 0 ] = Xo ; for ( int i = 1 ; i < noOfRandomNums ; i ++ ) { randomNums [ i ] = ( randomNums [ i - 1 ] + c ) % m ; } } int main ( ) { int Xo = 3 ; int m = 15 ; int c = 2 ; int noOfRandomNums = 20 ; vector < int > randomNums ( noOfRandomNums ) ; additiveCongruentialMethod ( Xo , m , c , randomNums , noOfRandomNums ) ; for ( int i = 0 ; i < noOfRandomNums ; i ++ ) { cout << randomNums [ i ] << " ▁ " ; } return 0 ; }
Number of ways to change the Array such that largest element is LCM of array | C ++ implementation to find the Number of ways to change the array such that maximum element of the array is the LCM of the array ; Modulo ; Fenwick tree to find number of indexes greater than x ; Function to compute x ^ y % MOD ; Loop to compute the x ^ y % MOD ; Function to update the binary indexed tree ; Function to find the prefix sum upto the current index ; Function to find the number of ways to change the array such that the LCM of array is maximum element of the array ; Updating BIT with the frequency of elements ; Maximum element in the array ; 1 is for every element is 1 in the array ; ; Vector for storing the factors ; finding factors of i ; Sorting in descending order ; for storing number of indexex greater than the i - 1 element ; Number of remaining factors ; Number of indexes in the array with element factor [ j ] and above ; Multiplying count with remFcators ^ ( indexes - prev ) ; Remove those counts which have lcm as i but i is not present ; Loop to find the count which have lcm as i but i is not present ; Adding cnt - toSubtract to answer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MOD = 1e9 + 7 ; const int N = 1e5 + 5 ; vector < int > BIT ( N , 0 ) ; int power ( int x , int y ) { if ( x == 0 ) return 0 ; int ans = 1 ; while ( y > 0 ) { if ( y & 1 ) ans = ( 1LL * ans * x ) % MOD ; x = ( 1LL * x * x ) % MOD ; y >>= 1 ; } return ans ; } void updateBIT ( int idx , int val ) { assert ( idx > 0 ) ; while ( idx < N ) { BIT [ idx ] += val ; idx += idx & - idx ; } } int queryBIT ( int idx ) { int ans = 0 ; while ( idx > 0 ) { ans += BIT [ idx ] ; idx -= idx & - idx ; } return ans ; } int numWays ( int arr [ ] , int n ) { int mx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { updateBIT ( arr [ i ] , 1 ) ; mx = max ( mx , arr [ i ] ) ; } int ans = 1 ; for ( int i = 2 ; i <= mx ; i ++ ) { vector < int > factors ; for ( int j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { factors . push_back ( j ) ; if ( i / j != j ) factors . push_back ( i / j ) ; } } sort ( factors . rbegin ( ) , factors . rend ( ) ) ; int cnt = 1 ; int prev = 0 ; for ( int j = 0 ; j < factors . size ( ) ; j ++ ) { int remFactors = int ( factors . size ( ) ) - j ; int indexes = n - queryBIT ( factors [ j ] - 1 ) ; cnt = ( 1LL * cnt * power ( remFactors , indexes - prev ) ) % MOD ; prev = max ( prev , indexes ) ; } factors . erase ( factors . begin ( ) ) ; int toSubtract = 1 ; prev = 0 ; for ( int j = 0 ; j < factors . size ( ) ; j ++ ) { int remFactors = int ( factors . size ( ) ) - j ; int indexes = n - queryBIT ( factors [ j ] - 1 ) ; toSubtract = ( 1LL * toSubtract * power ( remFactors , indexes - prev ) ) ; prev = max ( prev , indexes ) ; } ans = ( 1LL * ans + cnt - toSubtract + MOD ) % MOD ; } return ans ; } int main ( ) { int arr [ ] = { 6 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int ans = numWays ( arr , n ) ; cout << ans << endl ; return 0 ; }
Second decagonal numbers | C ++ implementation to find N - th term in the series ; Function to find N - th term in the series ; Driver Code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; void findNthTerm ( int n ) { cout << n * ( 4 * n + 3 ) << endl ; } int main ( ) { int N = 4 ; findNthTerm ( N ) ; return 0 ; }
65537 | C ++ implementation for above approach ; Function to find the nth 65537 - gon Number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int gonNum65537 ( int n ) { return ( 65535 * n * n - 65533 * n ) / 2 ; } int main ( ) { int n = 3 ; cout << gonNum65537 ( n ) ; return 0 ; }
Hexacontatetragon numbers | C ++ implementation for above approach ; Function to Find the Nth Hexacontatetragon Number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int HexacontatetragonNum ( int n ) { return ( 62 * n * n - 60 * n ) / 2 ; } int main ( ) { int n = 3 ; cout << HexacontatetragonNum ( n ) ; return 0 ; }