codeparrot/xlcost-text-to-code huggingface dataset:
Count of the non | C ++ program to find count of non - prime divisors of given number ; Function to factors of the given number ; Loop to find the divisors of the number 2 ; Loop to find the divisors of the given number upto SQRT ( N ) ; Condition to check if the rest number is also a prime number ; Function to find the non - prime divisors of the given number ; Loop to count the number of the total divisors of given number ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < int > getFactorization ( int x ) { int count = 0 ; vector < int > v ; while ( x % 2 == 0 ) { count ++ ; x = x / 2 ; } if ( count != 0 ) v . push_back ( count ) ; for ( int i = 3 ; i <= sqrt ( x ) ; i += 2 ) { count = 0 ; while ( x % i == 0 ) { count ++ ; x /= i ; } if ( count != 0 ) v . push_back ( count ) ; } if ( x > 1 ) { v . push_back ( 1 ) ; } return v ; } int nonPrimeDivisors ( int N ) { vector < int > v = getFactorization ( N ) ; int ret = 1 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) ret = ret * ( v [ i ] + 1 ) ; ret = ret - v . size ( ) ; return ret ; } int main ( ) { int N = 8 ; cout << nonPrimeDivisors ( N ) << endl ; return 0 ; }
Check if a number is Full Fibonacci or not | C ++ program to check if a given number is a Full Fibonacci Number or not ; A utility function that returns true if x is perfect square ; Returns true if N is a Fibonacci Number and false otherwise ; N is Fibonacci if one of 5 * N ^ 2 + 4 or 5 * N ^ 2 - 4 or both is a perferct square ; Function to check digits ; Check if all digits are fibonacci or not ; Extract digit ; Check if the current digit is not fibonacci ; Function to check and return if N is a Full Fibonacci number or not ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPerfectSquare ( int x ) { int s = sqrt ( x ) ; return ( s * s == x ) ; } bool isFibonacci ( int n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } bool checkDigits ( int n ) { while ( n ) { int dig = n % 10 ; if ( dig == 4 && dig == 6 && dig == 7 && dig == 9 ) return false ; n /= 10 ; } return true ; } int isFullfibonacci ( int n ) { return ( checkDigits ( n ) && isFibonacci ( n ) ) ; } int main ( ) { int n = 13 ; if ( isFullfibonacci ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Check whether a large number is divisible by 53 or not | C ++ program to check whether a number is divisible by 53 or not ; Function to check if the number is divisible by 53 or not ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDivisible ( string s ) { int flag = 0 ; while ( s . size ( ) > 4 ) { int l = s . size ( ) - 1 ; int x = ( s [ l ] - '0' ) * 37 ; reverse ( s . begin ( ) , s . end ( ) ) ; s . erase ( 0 , 1 ) ; int i = 0 , carry = 0 ; while ( x ) { int d = ( s [ i ] - '0' ) - ( x % 10 ) - carry ; if ( d < 0 ) { d += 10 ; carry = 1 ; } else carry = 0 ; s [ i ] = ( char ) ( d + '0' ) ; x /= 10 ; i ++ ; } while ( carry && i < l ) { int d = ( s [ i ] - '0' ) - carry ; if ( d < 0 ) { d += 10 ; carry = 1 ; } else carry = 0 ; s [ i ] = ( char ) ( d + '0' ) ; i ++ ; } reverse ( s . begin ( ) , s . end ( ) ) ; } int num = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { num = num * 10 + ( s [ i ] - '0' ) ; } if ( num % 53 == 0 ) return true ; else return false ; } int main ( ) { string N = "18432462191076" ; if ( isDivisible ( N ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }
Check whether two numbers are in silver ratio | C ++ implementation to check whether two numbers are in silver ratio with each other ; Function to check that two numbers are in silver ratio ; Swapping the numbers such that A contains the maximum number between these numbers ; First Ratio ; Second Ratio ; Condition to check that two numbers are in silver ratio ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checksilverRatio ( float a , float b ) { if ( a < b ) swap ( a , b ) ; float ratio1 = ( ( a / b ) * 1000.0 ) / 1000.0 ; float ratio2 = ( int ) ( ( ( 2 * a + b ) / a ) * 1000 ) ; ratio2 = ratio2 / 1000 ; if ( ratio1 == ratio2 && ( int ) ( ratio1 - 2.414 ) == 0 ) { cout << " Yes STRNEWLINE " ; return true ; } else { cout << " No STRNEWLINE " ; return false ; } } int main ( ) { float a = 2.414 ; float b = 1 ; checksilverRatio ( a , b ) ; }
Nth term where K + 1 th term is product of Kth term with difference of max and min digit of Kth term | C ++ implementation to find the value of the given function for the value ; Function to find minimum digit in the decimal representation of N ; Loop to find the minimum digit in the number ; Function to find maximum digit in the decimal representation of N ; Loop to find the maximum digit in the number ; Function to find the value of the given function ; Loop to compute the values of the given number ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int MIN ( int n ) { int ans = 11 ; while ( n ) { ans = min ( ans , n % 10 ) ; n /= 10 ; } return ans ; } int MAX ( int n ) { int ans = -1 ; while ( n ) { ans = max ( ans , n % 10 ) ; n /= 10 ; } return ans ; } void Find_value ( int n , int k ) { k -- ; int x = 0 ; int y = 0 ; while ( k -- ) { x = MIN ( n ) ; y = MAX ( n ) ; if ( y - x == 0 ) break ; n *= ( y - x ) ; } cout << n ; } int main ( ) { int N = 487 , D = 5 ; Find_value ( N , D ) ; return 0 ; }
Program to check if N is a Decagonal Number | C ++ program for the above approach ; Function to check if N is a Decagonal Number ; Condition to check if the number is a decagonal number ; Driver Code ; Given Number ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isdecagonal ( int N ) { float n = ( 3 + sqrt ( 16 * N + 9 ) ) / 8 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int N = 10 ; if ( isdecagonal ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Program to check if N is a Octadecagon number | C ++ program for the above approach ; Function to check if N is a Octadecagon Number ; Condition to check if the number is a Octadecagon number ; Driver Code ; Given Number ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isOctadecagon ( int N ) { float n = ( 14 + sqrt ( 128 * N + 196 ) ) / 32 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int N = 18 ; if ( isOctadecagon ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Count of subsequences which consists exactly K prime numbers | C ++ implementation to find the count of subsequences which consist exactly K primes ; Returns factorial of n ; Function to return total number of combinations ; Function check whether a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Function for finding number of subsequences which consists exactly K primes ; if number of primes are less thn k ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } int countSubsequences ( int arr [ ] , int n , int k ) { int countPrime = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPrime ( arr [ i ] ) ) countPrime ++ ; } if ( countPrime < k ) return 0 ; return nCr ( countPrime , k ) * pow ( 2 , ( n - countPrime ) ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; int K = 3 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSubsequences ( arr , n , K ) ; return 0 ; }
Length of the longest alternating even odd subarray | C ++ program to find the Length of the longest alternating even odd subarray ; Function to find the longest subarray ; Length of longest alternating subarray ; Iterate in the array ; increment count if consecutive elements has an odd sum ; Store maximum count in longest ; Reinitialize cnt as 1 consecutive elements does not have an odd sum ; Length of ' longest ' can never be 1 since even odd has to occur in pair or more so return 0 if longest = 1 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int longestEvenOddSubarray ( int a [ ] , int n ) { int longest = 1 ; int cnt = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( ( a [ i ] + a [ i + 1 ] ) % 2 == 1 ) { cnt ++ ; } else { longest = max ( longest , cnt ) ; cnt = 1 ; } } if ( longest == 1 ) return 0 ; return max ( cnt , longest ) ; } int main ( ) { int a [ ] = { 1 , 2 , 3 , 4 , 5 , 7 , 8 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << longestEvenOddSubarray ( a , n ) ; return 0 ; }
Check whether given number N is a Moran Number or not | C ++ implementation to check if the number is Moran number ; Function to calculate digit sum ; Function to check if number is prime ; Function to check if number is moran number ; Calculate digit sum ; Check if n is completely divisible by digit sum ; Calculate the quotient ; Check if the number is prime ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int digSum ( int a ) { int sum = 0 ; while ( a ) { sum += a % 10 ; a = a / 10 ; } return sum ; } bool isPrime ( int r ) { bool s = true ; for ( int i = 2 ; i * i <= r ; i ++ ) { if ( r % i == 0 ) { s = false ; break ; } } return s ; } void moranNo ( int n ) { int dup = n ; int sum = digSum ( dup ) ; if ( n % sum == 0 ) { int c = n / sum ; if ( isPrime ( c ) ) { cout << " Yes " ; return ; } } cout << " No " << endl ; } int main ( ) { int n = 21 ; moranNo ( n ) ; return 0 ; }
Program to check if N is a Hendecagonal Number | C ++ program for the above approach ; Function to check if N is a Hendecagonal Number ; Condition to check if the number is a hendecagonal number ; Driver Code ; Given Number ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool ishendecagonal ( int N ) { float n = ( 7 + sqrt ( 72 * N + 49 ) ) / 18 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int N = 11 ; if ( ishendecagonal ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Program to check if N is a Hexadecagonal Number | C ++ program for the above approach ; Function to check if N is a hexadecagonal number ; Condition to check if the number is a hexadecagonal number ; Driver Code ; Given Number ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool ishexadecagonal ( int N ) { float n = ( 12 + sqrt ( 112 * N + 144 ) ) / 28 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int N = 16 ; if ( ishexadecagonal ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Program to check if N is a Nonagonal Number | C ++ program for the above approach ; Function to check if N is a is a Nonagonal Number ; Condition to check if the number is a nonagonal number ; Driver Code ; Given Number ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isnonagonal ( int N ) { float n = ( 5 + sqrt ( 56 * N + 25 ) ) / 14 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int N = 9 ; if ( isnonagonal ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Count of decreasing pairs formed from numbers 1 to N | C ++ program to count decreasing pairs formed from numbers 1 to N ; Function to count the possible number of pairs ; if the number is even then the answer in ( N / 2 ) - 1 ; if the number is odd then the answer in N / 2 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int divParts ( int N ) { if ( N % 2 == 0 ) cout << ( N / 2 ) - 1 << endl ; else cout << N / 2 << endl ; } int main ( ) { int N = 8 ; divParts ( N ) ; return 0 ; }
Count the minimum steps to reach 0 from the given integer N | C ++ program to Count the minimum steps to reach 0 from the given integer N ; Function returns min step to reach 0 from N ; Direct possible reduction of value N ; Remaining steps needs to be reduced by 1 ; Summation of both the values ; Return the final answer ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getMinSteps ( int n , int jump ) { int quotient = n / jump ; int remainder = n % jump ; int steps = quotient + remainder ; return steps ; } int main ( ) { int N = 6 , K = 3 ; cout << getMinSteps ( N , K ) ; return 0 ; }
Construct an Array of size N whose sum of cube of all elements is a perfect square | C ++ implementation of the above approach ; Function to construct an array of size N ; Prints the first N natural numbers ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void constructArray ( int N ) { for ( int i = 1 ; i <= N ; i ++ ) { cout << i << " ▁ " ; } } int main ( ) { int N = 5 ; constructArray ( N ) ; return 0 ; }
Program to check if N is a Centered Decagonal Number | C ++ program for the above approach ; Function to check if number N is a Centered decagonal number ; Condition to check if N is Centered Decagonal Number ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isCentereddecagonal ( int N ) { float n = ( 5 + sqrt ( 20 * N + 5 ) ) / 10 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int N = 11 ; if ( isCentereddecagonal ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
C / C ++ program to add N distances given in inch | C ++ program for the above approach ; Struct defined for the inch - feet system ; Variable to store the inch - feet ; Function to find the sum of all N set of Inch Feet distances ; Variable to store sum ; Traverse the InchFeet array ; Find the total sum of feet and inch ; If inch sum is greater than 11 ; Find integral part of inch_sum ; Delete the integral part x ; Add x % 12 to inch_sum ; Add x / 12 to feet_sum ; Print the corresponding sum of feet_sum and inch_sum ; Driver Code ; Given a set of inch - feet ; Function Call
#include " iostream " NEW_LINE using namespace std ; struct InchFeet { int feet ; float inch ; } ; void findSum ( InchFeet arr [ ] , int N ) { int feet_sum = 0 ; float inch_sum = 0.0 ; int x ; for ( int i = 0 ; i < N ; i ++ ) { feet_sum += arr [ i ] . feet ; inch_sum += arr [ i ] . inch ; } if ( inch_sum >= 12 ) { int x = ( int ) inch_sum ; inch_sum -= x ; inch_sum += x % 12 ; feet_sum += x / 12 ; } cout << " Feet ▁ Sum : ▁ " << feet_sum << ' ' << " Inch ▁ Sum : ▁ " << inch_sum << endl ; } int main ( ) { InchFeet arr [ ] = { { 10 , 3.7 } , { 10 , 5.5 } , { 6 , 8.0 } } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findSum ( arr , N ) ; return 0 ; }
Count Sexy Prime Pairs in the given array | C ++ program to count Sexy Prime pairs in array ; A utility function to check if the number n is prime or not ; Base Cases ; Check to skip middle five numbers in below loop ; If n is divisible by i and i + 2 then it is not prime ; A utility function that check if n1 and n2 are SPP ( Sexy Prime Pair ) or not ; Function to find SPP ( Sexy Prime Pair ) pairs from the given array ; Iterate through all pairs ; Increment count if SPP ( Sexy Prime Pair ) pair ; Driver code ; Function call to find SPP ( Sexy Prime Pair ) pair
#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 += 6 ) { if ( n % i == 0 || n % ( i + 6 ) == 0 ) { return false ; } } return true ; } bool SexyPrime ( int n1 , int n2 ) { return ( isPrime ( n1 ) && isPrime ( n2 ) && abs ( n1 - n2 ) == 6 ) ; } int countSexyPairs ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( SexyPrime ( arr [ i ] , arr [ j ] ) ) { count ++ ; } } } return count ; } int main ( ) { int arr [ ] = { 6 , 7 , 5 , 11 , 13 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSexyPairs ( arr , n ) ; return 0 ; }
Find the K | C ++ program to Find the kth Permutation Sequence of first n natural numbers ; Function to find the index of number at first position of kth sequence of set of size n ; n_actual_fact = n ! ; First position of the kth sequence will be occupied by the number present at index = k / ( n - 1 ) ! ; Function to find the kth permutation of n numbers ; Store final answer ; Insert all natural number upto n in set ; Mark the first position ; subtract 1 to get 0 based indexing ; itr now points to the number at index in set s ; remove current number from the set ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findFirstNumIndex ( int & k , int n ) { if ( n == 1 ) return 0 ; n -- ; int first_num_index ; int n_partial_fact = n ; while ( k >= n_partial_fact && n > 1 ) { n_partial_fact = n_partial_fact * ( n - 1 ) ; n -- ; } first_num_index = k / n_partial_fact ; k = k % n_partial_fact ; return first_num_index ; } string findKthPermutation ( int n , int k ) { string ans = " " ; set < int > s ; for ( int i = 1 ; i <= n ; i ++ ) s . insert ( i ) ; set < int > :: iterator itr ; itr = s . begin ( ) ; k = k - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int index = findFirstNumIndex ( k , n - i ) ; advance ( itr , index ) ; ans += ( to_string ( * itr ) ) ; s . erase ( itr ) ; itr = s . begin ( ) ; } return ans ; } int main ( ) { int n = 3 , k = 4 ; string kth_perm_seq = findKthPermutation ( n , k ) ; cout << kth_perm_seq << endl ; return 0 ; }
Find the Largest N digit perfect square number in Base B | C ++ implementation to find Largest N digit perfect square number in Base B ; Function to find the largest N digit number ; Largest n - digit perfect square ; Print the result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void nDigitPerfectSquares ( int n , int b ) { int largest = pow ( ceil ( sqrt ( pow ( b , n ) ) ) - 1 , 2 ) ; cout << largest ; } int main ( ) { int N = 1 , B = 8 ; nDigitPerfectSquares ( N , B ) ; return 0 ; }
Find Cube root of a number using Log function | C ++ program to Find Cube root of a number using Logarithm ; Function to find the cube root ; calculate the cube root ; Return the final answer ; Driver code
#include <bits/stdc++.h> NEW_LINE double cubeRoot ( double n ) { double ans = pow ( 3 , ( 1.0 / 3 ) * ( log ( n ) / log ( 3 ) ) ) ; return ans ; } int main ( ) { double N = 8 ; printf ( " % .2lf ▁ " , cubeRoot ( N ) ) ; return 0 ; }
Find the maximum possible value for the given periodic function | C ++ Program to find the maximum possible value for the given function ; Function to return the maximum value of f ( x ) ; Driver code
#include <iostream> NEW_LINE using namespace std ; int floorMax ( int A , int B , int N ) { int x = min ( B - 1 , N ) ; return ( A * x ) / B ; } int main ( ) { int A = 11 , B = 10 , N = 9 ; cout << floorMax ( A , B , N ) ; return 0 ; }
Minimum moves taken to move coin of each cell to any one cell of Matrix | C ++ program to find the minimum number of moves taken to move the element of each cell to any one cell of the square matrix of odd length ; Function to find the minimum number of moves taken to move the element of each cell to any one cell of the square matrix of odd length ; Initializing count to 0 ; Number of layers that are around the centre element ; Iterating over ranger of layers ; Increase the value of count by 8 * k * k ; Driver code
#include <iostream> NEW_LINE using namespace std ; int calculateMoves ( int n ) { int count = 0 ; int layers = n / 2 ; for ( int k = 1 ; k < layers + 1 ; k ++ ) { count += 8 * k * k ; } return count ; } int main ( ) { int N = 5 ; cout << calculateMoves ( N ) ; }
Check if N can be represented as sum of squares of two consecutive integers | C ++ implementation to check that a number is sum of squares of 2 consecutive numbers or not ; Function to check that the a number is sum of squares of 2 consecutive numbers or not ; Condition to check if the a number is sum of squares of 2 consecutive numbers or not ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isSumSquare ( int N ) { float n = ( 2 + sqrt ( 8 * N - 4 ) ) / 2 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int i = 13 ; if ( isSumSquare ( i ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Program to check if N is a Centered heptagonal number | C ++ implementation to check that a number is a Centered heptagonal number or not ; Function to check that the number is a Centered heptagonal number ; Condition to check if the number is a Centered heptagonal number ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isCenteredheptagonal ( int N ) { float n = ( 7 + sqrt ( 56 * N - 7 ) ) / 14 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int n = 8 ; if ( isCenteredheptagonal ( n ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Program to check if N is a Centered nonadecagonal number | C ++ implementation to check that a number is a Centered nonadecagonal number or not ; Function to check that the number is a Centered nonadecagonal number ; Condition to check if the number is a Centered nonadecagonal number ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isCenterednonadecagonal ( int N ) { float n = ( 19 + sqrt ( 152 * N + 209 ) ) / 38 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int n = 20 ; if ( isCenterednonadecagonal ( n ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Program to check if N is a Centered Octadecagonal number | C ++ implementation to check that a number is a Centered Octadecagonal number or not ; Function to check that the number is a Centered Octadecagonal number ; Implement the formula generated ; Condition to check if the number is a Centered Octadecagonal number ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isCenteredOctadecagonal ( int N ) { float n = ( 9 + sqrt ( 36 * N + 45 ) ) / 18 ; return ( n - ( int ) n ) == 0 ; } int main ( ) { int n = 19 ; if ( isCenteredOctadecagonal ( n ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Logarithm tricks for Competitive Programming | C ++ implementation to find Kth root of the number ; Function to find the Kth root of the number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double kthRoot ( double n , int k ) { return pow ( k , ( 1.0 / k ) * ( log ( n ) / log ( k ) ) ) ; } int main ( ) { double N = 8.0 ; int K = 3 ; cout << kthRoot ( N , K ) ; return 0 ; }
Logarithm tricks for Competitive Programming | C ++ implementation to check if the number is power of K ; Function to check if the number is power of K ; logarithm function to calculate value ; compare to the result1 or result2 both are equal ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPower ( int N , int K ) { int res1 = log ( N ) / log ( K ) ; double res2 = log ( N ) / log ( K ) ; return ( res1 == res2 ) ; } int main ( ) { int N = 8 ; int K = 2 ; if ( isPower ( N , K ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Count of subarrays which start and end with the same element | C ++ program to Count total sub - array which start and end with same element ; function to find total sub - array which start and end with same element ; initialize result with 0 ; array to count frequency of 1 to N ; update frequency of A [ i ] ; update result with sub - array contributed by number i ; print the result ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void cntArray ( int A [ ] , int N ) { int result = 0 ; int frequency [ N + 1 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { frequency [ A [ i ] ] ++ ; } for ( int i = 1 ; i <= N ; i ++ ) { int frequency_of_i = frequency [ i ] ; result += + ( ( frequency_of_i ) * ( frequency_of_i + 1 ) ) / 2 ; } cout << result << endl ; } int main ( ) { int A [ ] = { 1 , 5 , 6 , 1 , 9 , 5 , 8 , 10 , 8 , 9 } ; int N = sizeof ( A ) / sizeof ( int ) ; cntArray ( A , N ) ; return 0 ; }