codeparrot/xlcost-text-to-code huggingface dataset:
Number of factors of very large number N modulo M where M is any prime number | C ++ implementation to find the Number of factors of very large number N modulo M ; Function for modular multiplication ; Function to find the number of factors of large Number N ; Count the number of times 2 divides the number N ; Condition to check if 2 divides it ; Check for all the possible numbers that can divide it ; Loop to check the number of times prime number i divides it ; Condition to check if prime number i divides it ; Condition to check if N at the end is a prime number . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE ll mod = 1000000007 ; ll mult ( ll a , ll b ) { return ( ( a % mod ) * ( b % mod ) ) % mod ; } ll calculate_factors ( ll n ) { ll ans , cnt ; cnt = 0 ; ans = 1 ; while ( n % 2 == 0 ) { cnt ++ ; n = n / 2 ; } if ( cnt ) { ans = mult ( ans , ( cnt + 1 ) ) ; } for ( int i = 3 ; i <= sqrt ( n ) ; i += 2 ) { cnt = 0 ; while ( n % i == 0 ) { cnt ++ ; n = n / i ; } if ( cnt ) { ans = mult ( ans , ( cnt + 1 ) ) ; } } if ( n > 2 ) { ans = mult ( ans , ( 2 ) ) ; } return ans % mod ; } int main ( ) { ll n = 193748576239475639 ; mod = 17 ; cout << calculate_factors ( n ) << endl ; return 0 ; }
Maximum value of B less than A such that A ^ B = A + B | C ++ implementation to find maximum value of B such that A ^ B = A + B ; Function to find the maximum value of B such that A ^ B = A + B ; Binary Representation of A ; Loop to find the negation of the integer A ; Output ; Driver code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void maxValue ( int a ) { string c = bitset < 3 > ( a ) . to_string ( ) ; string b = " " ; for ( int i = 0 ; i < c . length ( ) ; i ++ ) { if ( ( c [ i ] - '0' ) == 1 ) b += '0' ; else b += '1' ; } cout << bitset < 3 > ( b ) . to_ulong ( ) ; } int main ( ) { int a = 4 ; maxValue ( a ) ; return 0 ; }
Print all possible pair with prime XOR in the Array | C ++ implementation of the above approach ; Function for Sieve of Eratosthenes ; If i is prime , then make all multiples of i false ; Function to print all Pairs whose XOR is prime ; if A [ i ] ^ A [ j ] is prime , then print this pair ; Driver Code ; Generate all the prime number ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int sz = 1e5 ; bool isPrime [ sz + 1 ] ; void generatePrime ( ) { int i , j ; memset ( isPrime , true , sizeof ( isPrime ) ) ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } void Pair_of_PrimeXor ( int A [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( isPrime [ ( A [ i ] ^ A [ j ] ) ] ) { cout << " ( " << A [ i ] << " , ▁ " << A [ j ] << " ) ▁ " ; } } } } int main ( ) { int A [ ] = { 1 , 3 , 6 , 11 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; generatePrime ( ) ; Pair_of_PrimeXor ( A , n ) ; return 0 ; }
Check if N can be expressed as product of 3 distinct numbers | C ++ program to find the three numbers ; function to find 3 distinct number with given product ; Declare a vector to store divisors ; store all divisors of number in array ; store all the occurence of divisors ; check if n is not equals to - 1 then n is also a prime factor ; Initialize the variables with 1 ; check for first number a ; check for second number b ; check for third number c ; check for all unwanted condition ; Driver function
#include " bits / stdc + + . h " NEW_LINE using namespace std ; void getnumbers ( int n ) { vector < int > divisor ; for ( int i = 2 ; i * i <= n ; i ++ ) { while ( n % i == 0 ) { divisor . push_back ( i ) ; n /= i ; } } if ( n != 1 ) { divisor . push_back ( n ) ; } int a , b , c , size ; a = b = c = 1 ; size = divisor . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { if ( a == 1 ) { a = a * divisor [ i ] ; } else if ( b == 1 b == a ) { b = b * divisor [ i ] ; } else { c = c * divisor [ i ] ; } } if ( a == 1 b == 1 c == 1 a == b b == c a == c ) { cout << " - 1" << endl ; } else { cout << a << ' ▁ ' << b << ' ▁ ' << c << endl ; } } int main ( ) { int n = 64 ; getnumbers ( n ) ; }
Check if all Prime factors of number N are unique or not | C ++ program for the above approach ; Function that returns the all the distinct prime factors in a vector ; If n is divisible by 2 ; Divide n till all factors of 2 ; Check for the prime numbers other than 2 ; Store i in Prime [ ] i is a factor of n ; Divide n till all factors of i ; If n is greater than 2 , then n is prime number after n divided by all factors ; Returns the vector Prime ; Function that check whether N is the product of distinct prime factors or not ; Returns the vector to store all the distinct prime factors ; To find the product of all distinct prime factors ; Find the product ; If product is equals to N , print YES , else print NO ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < int > primeFactors ( int n ) { int i , j ; vector < int > Prime ; if ( n % 2 == 0 ) { Prime . push_back ( 2 ) ; } while ( n % 2 == 0 ) { n = n / 2 ; } for ( i = 3 ; i <= sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { Prime . push_back ( i ) ; } while ( n % i == 0 ) { n = n / i ; } } if ( n > 2 ) { Prime . push_back ( n ) ; } return Prime ; } void checkDistinctPrime ( int n ) { vector < int > Prime = primeFactors ( n ) ; int product = 1 ; for ( auto i : Prime ) { product *= i ; } if ( product == n ) cout << " YES " ; else cout << " NO " ; } int main ( ) { int N = 30 ; checkDistinctPrime ( N ) ; return 0 ; }
Count perfect power of K in a range [ L , R ] | C ++ implementation to find the count of numbers those are powers of K in range L to R ; Function to find the Nth root of the number ; initially guessing a random number between 0 to 9 ; Smaller eps , denotes more accuracy ; Initializing difference between two roots by INT_MAX ; xK denotes current value of x ; loop until we reach desired accuracy ; calculating current value from previous value ; Function to count the perfect powers of K in range L to R ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double nthRoot ( int A , int N ) { double xPre = rand ( ) % 10 ; double eps = 1e-3 ; double delX = INT_MAX ; double xK ; while ( delX > eps ) { xK = ( ( N - 1.0 ) * xPre + ( double ) A / pow ( xPre , N - 1 ) ) / ( double ) N ; delX = abs ( xK - xPre ) ; xPre = xK ; } return xK ; } int countPowers ( int a , int b , int k ) { return ( floor ( nthRoot ( b , k ) ) - ceil ( nthRoot ( a , k ) ) + 1 ) ; } int main ( ) { int a = 7 , b = 28 , k = 2 ; cout << " Count ▁ of ▁ Powers ▁ is ▁ " << countPowers ( a , b , k ) ; return 0 ; }
Minimum number of primes required such that their sum is equal to N | C ++ program for the above approach ; Function to check if n is prime ; Function to count the minimum prime required for given sum N ; Case 1 : ; Case 2 : ; Case 3 : ; Case 3 a : ; Case 3 b : ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPrime ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return false ; } } return true ; } void printMinCountPrime ( int N ) { int minCount ; if ( isPrime ( N ) ) { minCount = 1 ; } else if ( N % 2 == 0 ) { minCount = 2 ; } else { if ( isPrime ( N - 2 ) ) { minCount = 2 ; } else { minCount = 3 ; } } cout << minCount << endl ; } int main ( ) { int N = 100 ; printMinCountPrime ( N ) ; return 0 ; }
Long Division Method to find Square root with Examples | C ++ program to find the square root of a number by using long division method ; Function to find the square root of a number by using long division method ; int i = 0 , udigit , j ; Loop counters ; Dividing the number into segments ; Last index of the array of segments ; Start long division from the last segment ( j = i ) ; Initialising the remainder to the maximum value ; Including the next segment in new dividend ; Loop to check for the perfect square closest to each segment ; This condition is to find the divisor after adding a digit in the range 0 to 9 ; Calculating the remainder ; Updating the units digit of the quotient ; Adding units digit to the quotient ; New divisor is two times quotient ; Including the remainder in new dividend ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define INFINITY_  9999999 NEW_LINE int sqrtByLongDivision ( int n ) { int cur_divisor = 0 ; int quotient_units_digit = 0 ; int cur_quotient = 0 ; int cur_dividend = 0 ; int cur_remainder = 0 ; int a [ 10 ] = { 0 } ; while ( n > 0 ) { a [ i ] = n % 100 ; n = n / 100 ; i ++ ; } i -- ; for ( j = i ; j >= 0 ; j -- ) { cur_remainder = INFINITY_ ; cur_dividend = cur_dividend * 100 + a [ j ] ; for ( udigit = 0 ; udigit <= 9 ; udigit ++ ) { if ( cur_remainder >= cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) && cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) >= 0 ) { cur_remainder = cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) ; quotient_units_digit = udigit ; } } cur_quotient = cur_quotient * 10 + quotient_units_digit ; cur_divisor = cur_quotient * 2 ; cur_dividend = cur_remainder ; } return cur_quotient ; } int main ( ) { int x = 1225 ; cout << sqrtByLongDivision ( x ) << endl ; return 0 ; }
Count of consecutive Fibonacci pairs in the given Array | C ++ implementation to count the consecutive fibonacci pairs in the array ; Function to find the previous fibonacci for the number N ; Function to find the next fibonacci number for the number N ; Function to check that a Number is a perfect square or not ; Function to check that a number is fibonacci number or not ; N is Fibinacci if one of ( 5 * n * n + 4 ) or ( 5 * n * n - 4 ) is a perferct square ; Function to count the fibonacci pairs in the array ; Loop to iterate over the array to choose all pairs of the array ; Condition to check if both the number of pair is a fibonacci number ; Condition to check if both the number form consecutive fibonacci numbers ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int previousFibonacci ( int n ) { double a = n / ( ( 1 + sqrt ( 5 ) ) / 2.0 ) ; return round ( a ) ; } int nextFibonacci ( int n ) { double a = n * ( 1 + sqrt ( 5 ) ) / 2.0 ; return round ( a ) ; } 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 ) ) ; } int countFibonacciPairs ( int arr [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( isFibonacci ( arr [ i ] ) && isFibonacci ( arr [ j ] ) ) { int prevFib = previousFibonacci ( arr [ i ] ) ; int nextFib = nextFibonacci ( arr [ i ] ) ; if ( prevFib == arr [ j ] nextFib == arr [ j ] ) { res ++ ; } } return res ; } int main ( ) { int a [ ] = { 3 , 5 , 8 , 11 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << countFibonacciPairs ( a , n ) ; return 0 ; }
Count all distinct pairs with product equal to K | C ++ program to count the number of pairs whose product is equal to K ; Function to count the number of pairs whose product is equal to K ; Pick all elements one by one ; Check if the product of this pair is equal to K ; Driver code
#include <iostream> NEW_LINE using namespace std ; int countPairsWithProdK ( int arr [ ] , int n , int k ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] * arr [ j ] == k ) count ++ ; } return count ; } int main ( ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << countPairsWithProdK ( arr , N , K ) ; return 0 ; }
Count all distinct pairs with product equal to K | C ++ program to count the number of pairs whose product is equal to K ; Function to count the number of pairs whose product is equal to K ; Initialize the count ; Initialize empty hashmap . ; Insert array elements to hashmap ; Checking if the index is a whole number and present in the hashmap ; Driver code
#include <algorithm> NEW_LINE #include <iostream> NEW_LINE using namespace std ; #define MAX  100000 NEW_LINE int countPairsWithProductK ( int arr [ ] , int n , int k ) { int count = 0 ; bool hashmap [ MAX ] = { false } ; for ( int i = 0 ; i < n ; i ++ ) hashmap [ arr [ i ] ] = true ; for ( int i = 0 ; i < n ; i ++ ) { int x = arr [ i ] ; double index = 1.0 * k / arr [ i ] ; if ( index >= 0 && ( ( index - ( int ) ( index ) ) == 0 ) && hashmap [ k / x ] ) count ++ ; hashmap [ x ] = false ; } return count ; } int main ( ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << countPairsWithProductK ( arr , N , K ) ; return 0 ; }
Find any K distinct odd integers such that their sum is equal to N | C ++ implementation to find k odd integers such that their sum is N ; Function to find K odd integers such that their sum is N ; Condition to check if there exist such K integers ; Loop to find first K - 1 distinct odd integers ; Final Kth odd number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void oddIntegers ( int n , int k ) { if ( n % 2 != k % 2 ) { cout << " - 1" << " STRNEWLINE " ; return ; } int sum = 0 ; int i = 1 ; int j = 1 ; while ( j < k ) { sum = sum + i ; cout << i << " ▁ " ; i = i + 2 ; j ++ ; } int finalOdd = n - sum ; cout << finalOdd << " STRNEWLINE " ; } int main ( ) { int n = 10 ; int k = 2 ; oddIntegers ( n , k ) ; return 0 ; }
Sum of product of proper divisors of all Numbers lying in range [ L , R ] | C ++ implementation to find the sum of the product of proper divisors of all the numbers lying in the range [ L , R ] ; Vector to store the product of the proper divisors of a number ; Variable to store the prefix sum of the product array ; Function to precompute the product of proper divisors of a number at it 's corresponding index ; Modificatino of sieve to store the product of the proper divisors ; Multiplying the existing value with i because i is the proper divisor of ans [ j ] ; Loop to store the prefix sum of the previously computed product array ; Computing the prefix sum ; Function to print the sum for each query ; Function to print te sum of product of proper divisors of a number in [ L , R ] ; Calling the function that pre computes the sum of product of proper divisors ; Iterate over all Queries to print the sum ; Driver code
#include <bits/stdc++.h> NEW_LINE #define ll  long long int NEW_LINE #define mod  1000000007 NEW_LINE using namespace std ; vector < ll > ans ( 100002 , 1 ) ; long long pref [ 100002 ] ; void preCompute ( ) { for ( int i = 2 ; i <= 100000 / 2 ; i ++ ) { for ( int j = 2 * i ; j <= 100000 ; j += i ) { ans [ j ] = ( ans [ j ] * i ) % mod ; } } for ( int i = 1 ; i < 100002 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + ans [ i ] ; pref [ i ] %= mod ; } } void printSum ( int L , int R ) { cout << pref [ R ] - pref [ L - 1 ] << " ▁ " ; } void printSumProper ( int arr [ ] [ 2 ] , int Q ) { preCompute ( ) ; for ( int i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } int main ( ) { int Q = 2 ; int arr [ ] [ 2 ] = { { 10 , 20 } , { 12 , 16 } } ; printSumProper ( arr , Q ) ; return 0 ; }
Generate an array of size N according to the given rules | C ++ implementation to generate an array of size N by following the given rules ; Function to search the most recent location of element N If not present in the array it will return - 1 ; Function to generate an array of size N by following the given rules ; Loop to fill the array as per the given rules ; Check for the occurrence of arr [ i - 1 ] ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int search ( int a [ ] , int k , int x ) { int j ; for ( j = k - 1 ; j > -1 ; j -- ) { if ( a [ j ] == x ) return j ; } return -1 ; } void genArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( search ( arr , i , arr [ i ] ) == -1 ) arr [ i + 1 ] = 0 ; else arr [ i + 1 ] = ( i - search ( arr , i , arr [ i ] ) ) ; } } int main ( ) { int N = 5 ; int size = N + 1 ; int a [ ] = { 0 , 0 , 0 , 0 , 0 } ; genArray ( a , N ) ; for ( int i = 0 ; i < N ; i ++ ) cout << a [ i ] << " ▁ " ; return 0 ; }
Count of pairs in an Array whose sum is a Perfect Cube | C ++ implementation of the approach ; Function to return an ArrayList containing all the perfect cubes upto n ; while current perfect cube is less than or equal to n ; Function to print the sum of maximum two elements from the array ; Function to return the count of numbers that when added with n give a perfect cube ; temp > n is checked so that pairs ( x , y ) and ( y , x ) don 't get counted twice ; Function to count the pairs whose sum is a perfect cube ; Sum of the maximum two elements from the array ; List of perfect cubes upto max ; Contains all the array elements ; Add count of the elements that when added with arr [ i ] give a perfect cube ; Driver code
#include <bits/stdc++.h> NEW_LINE #include <vector> NEW_LINE using namespace std ; vector < int > getPerfectcubes ( int n ) { vector < int > perfectcubes ; int current = 1 ; int i = 1 ; while ( current <= n ) { perfectcubes . push_back ( current ) ; i += 1 ; current = int ( pow ( i , 3 ) ) ; } return perfectcubes ; } int maxPairSum ( int arr [ ] , int n ) { int max = 0 ; int secondMax = 0 ; if ( arr [ 0 ] > arr [ 1 ] ) { max = arr [ 0 ] ; secondMax = arr [ 1 ] ; } else { max = arr [ 1 ] ; secondMax = arr [ 0 ] ; } for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { secondMax = max ; max = arr [ i ] ; } else if ( arr [ i ] > secondMax ) secondMax = arr [ i ] ; } return ( max + secondMax ) ; } int countPairsWith ( int n , vector < int > perfectcubes , vector < int > nums ) { int count = 0 ; int len = perfectcubes . size ( ) ; for ( int i = 0 ; i < len ; i ++ ) { int temp = perfectcubes [ i ] - n ; if ( temp > n ) { for ( auto j = nums . begin ( ) ; j != nums . end ( ) ; j ++ ) { if ( ( * j ) == temp ) count += 1 ; } } } return count ; } int countPairs ( int arr [ ] , int n ) { int max = maxPairSum ( arr , n ) ; vector < int > perfectcubes = getPerfectcubes ( max ) ; vector < int > nums ; for ( int i = 0 ; i < n ; i ++ ) nums . push_back ( arr [ i ] ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { count += countPairsWith ( arr [ i ] , perfectcubes , nums ) ; } return count ; } int main ( ) { int arr [ ] = { 2 , 6 , 18 , 9 , 999 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( countPairs ( arr , n ) ) ; }
Maximum Squares possible parallel to both axes from N distinct points | C ++ implementation of the approach ; Function that returns the count of squares parallel to both X and Y - axis from a given set of points ; Initialize result ; Initialize a set to store points ; Initialize a map to store the points in the same vertical line ; Store the points in a set ; Store the points in the same vertical line i . e . with same X co - ordinates ; Check for every two points in the same vertical line ; Check if other two point are present or not ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSquares ( int * X , int * Y , int N ) { int count = 0 ; set < pair < int , int > > points ; map < int , vector < int > > vertical ; for ( int i = 0 ; i < N ; i ++ ) { points . insert ( { X [ i ] , Y [ i ] } ) ; } for ( int i = 0 ; i < N ; i ++ ) { vertical [ X [ i ] ] . push_back ( Y [ i ] ) ; } for ( auto line : vertical ) { int X1 = line . first ; vector < int > yList = line . second ; for ( int i = 0 ; i < yList . size ( ) ; i ++ ) { int Y1 = yList [ i ] ; for ( int j = i + 1 ; j < yList . size ( ) ; j ++ ) { int Y2 = yList [ j ] ; int side = abs ( Y1 - Y2 ) ; int X2 = X1 + side ; if ( points . find ( { X2 , Y1 } ) != points . end ( ) and points . find ( { X2 , Y2 } ) != points . end ( ) ) count ++ ; } } } return count ; } int main ( ) { int X [ ] = { 0 , 2 , 0 , 2 } , Y [ ] = { 0 , 2 , 2 , 0 } ; int N = sizeof ( X ) / sizeof ( X [ 0 ] ) ; cout << countSquares ( X , Y , N ) ; return 0 ; }
Number of perfect cubes between two given numbers | A Simple Method to count cubes between a and b ; Function to count cubes between two numbers ; Traverse through all numbers ; Check if current number ' i ' is perfect cube ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countCubes ( int a , int b ) { for ( int i = a ; i <= b ; i ++ ) for ( int j = 1 ; j * j * j <= i ; j ++ ) if ( j * j * j == i ) cnt ++ ; return cnt ; } int main ( ) { int a = 7 , b = 30 ; cout << " Count ▁ of ▁ Cubes ▁ is ▁ " << countCubes ( a , b ) ; return 0 ; }
Number of perfect cubes between two given numbers | An Efficient Method to count cubes between a and b ; Function to count cubes between two numbers ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countCubes ( int a , int b ) { return ( floor ( cbrt ( b ) ) - ceil ( cbrt ( a ) ) + 1 ) ; } int main ( ) { int a = 7 , b = 28 ; cout << " Count ▁ of ▁ cubes ▁ is ▁ " << countCubes ( a , b ) ; return 0 ; }
XOR and OR of all N | C ++ program to find the XOR and OR of all Armstrong numbers of N digits ; Function to check if a number is Armstrong or not ; Function to find XOR of all N - digits Armstrong number ; To store the XOR and OR of all Armstrong number ; Starting N - digit Armstrong number ; Ending N - digit Armstrong number ; Iterate over starting and ending number ; To check if i is Armstrong or not ; Print the XOR and OR of all Armstrong number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isArmstrong ( int x , int n ) { int sum1 = 0 ; int temp = x ; while ( temp > 0 ) { int digit = temp % 10 ; sum1 += ( int ) pow ( digit , n ) ; temp /= 10 ; } return sum1 == x ; } void CalculateXORandOR ( int n ) { int CalculateXOR = 0 ; int CalculateOR = 0 ; int start = ( int ) pow ( 10 , n - 1 ) ; int end = ( int ) pow ( 10 , n ) - 1 ; for ( int i = start ; i < end + 1 ; i ++ ) { if ( isArmstrong ( i , n ) ) { CalculateXOR = CalculateXOR ^ i ; CalculateOR = CalculateOR | i ; } } cout << " XOR ▁ = ▁ " << CalculateXOR << endl ; cout << " OR ▁ = ▁ " << CalculateOR << endl ; } int main ( ) { int n = 4 ; CalculateXORandOR ( n ) ; }
Perfect Cube | C ++ program to check whether the given number N is the perfect cube or not ; Function to check if a number is a perfect Cube or not ; Iterate from 1 - N ; Find the cube of every number ; Check if cube equals N or not ; Driver code ; Function call
. #include <bits/stdc++.h> NEW_LINE using namespace std ; void perfectCube ( int N ) { int cube ; for ( int i ; i <= N ; i ++ ) { cube = i * i * i ; if ( cube == N ) { cout << " Yes " ; return ; } else if ( cube > N ) { cout << " NO " ; return ; } } } int main ( ) { int N = 216 ; perfectCube ( N ) ; return 0 ; }
Perfect Cube | C ++ program to check whether the given number N is the perfect cube or not ; Function to check if a number is a perfect Cube using inbuilt function ; If cube of cube_root is equals to N , then print Yes Else print No ; Driver 's code ; Function call to check N is cube or not
#include <bits/stdc++.h> NEW_LINE using namespace std ; void perfectCube ( int N ) { int cube_root ; cube_root = round ( cbrt ( N ) ) ; if ( cube_root * cube_root * cube_root == N ) { cout << " Yes " ; return ; } else { cout << " NO " ; return ; } } int main ( ) { int N = 125 ; perfectCube ( N ) ; return 0 ; }
Check if given array can be made 0 with given operations performed any number of times | C ++ implementation of the approach ; Function to whether the array can be made zero or not ; Count for even elements ; Count for odd elements ; Traverse the array to count the even and odd ; If arr [ i ] is odd ; If arr [ i ] is even ; Check if count of even is zero or count of odd is zero ; Driver 's Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( int arr [ ] , int N ) { int even = 0 ; int odd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & 1 ) { odd ++ ; } else { even ++ ; } } if ( even == N odd == N ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int arr [ ] = { 1 , 1 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; check ( arr , N ) ; return 0 ; }