codeparrot/xlcost-text-to-code huggingface dataset:
Find the k | C ++ program to find the K - th smallest factor ; Function to find the k 'th divisor ; initialize vectors v1 and v2 ; store all the divisors in the two vectors accordingly ; reverse the vector v2 to sort it in increasing order ; if k is greater than the size of vectors then no divisor can be possible ; else print the ( k - 1 ) th value of vector ; If K is lying in first vector ; If K is lying in second vector ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findkth ( int n , int k ) { vector < int > v1 ; vector < int > v2 ; for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v1 . push_back ( i ) ; if ( i != sqrt ( n ) ) v2 . push_back ( n / i ) ; } } reverse ( v2 . begin ( ) , v2 . end ( ) ) ; if ( k > ( v1 . size ( ) + v2 . size ( ) ) ) cout << " Doesn ' t ▁ Exist " ; else { if ( k <= v1 . size ( ) ) cout << v1 [ k - 1 ] ; else cout << v2 [ k - v1 . size ( ) - 1 ] ; } } int main ( ) { int n = 15 , k = 2 ; findkth ( n , k ) ; return 0 ; }
Number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y are integers | C ++ implementation of above approach ; function to Find the number of solutions for x < y , where a <= x <= b and c <= y <= d and x , y integers . ; to store answer ; iterate explicitly over all possible values of x ; return answer ; Driver code ; function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int NumberOfSolutions ( int a , int b , int c , int d ) { int ans = 0 ; for ( int i = a ; i <= b ; i ++ ) if ( d >= max ( c , i + 1 ) ) ans += d - max ( c , i + 1 ) + 1 ; return ans ; } int main ( ) { int a = 2 , b = 3 , c = 3 , d = 4 ; cout << NumberOfSolutions ( a , b , c , d ) ; return 0 ; }
Minimum value possible of a given function from the given set | C ++ implementation of above approach ; Function to find the value of F ( n ) ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE ll findF_N ( ll n ) { ll ans = 0 ; for ( ll i = 0 ; i < n ; ++ i ) ans += ( i + 1 ) * ( n - i - 1 ) ; return ans ; } int main ( ) { ll n = 3 ; cout << findF_N ( n ) ; return 0 ; }
Find N digits number which is divisible by D | CPP program to Find N digits number which is divisible by D ; Function to return N digits number which is divisible by D ; to store answer ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string findNumber ( int n , int d ) { string ans = " " ; if ( d != 10 ) { ans += to_string ( d ) ; for ( int i = 1 ; i < n ; i ++ ) ans += '0' ; } else { if ( n == 1 ) ans += " Impossible " ; else { ans += '1' ; for ( int i = 1 ; i < n ; i ++ ) ans += '0' ; } } return ans ; } int main ( ) { int n = 12 , d = 3 ; cout << findNumber ( n , d ) ; return 0 ; }
Count all the numbers less than 10 ^ 6 whose minimum prime factor is N | C ++ implementation of above approach ; the sieve of prime number and count of minimum prime factor ; form the prime sieve ; 1 is not a prime number ; form the sieve ; if i is prime ; if i is the least prime factor ; mark the number j as non prime ; count the numbers whose least prime factor is i ; Driver code ; form the sieve ; display ; display
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  1000000 NEW_LINE int sieve_Prime [ MAX + 4 ] = { 0 } , sieve_count [ MAX + 4 ] = { 0 } ; void form_sieve ( ) { sieve_Prime [ 1 ] = 1 ; for ( int i = 2 ; i <= MAX ; i ++ ) { if ( sieve_Prime [ i ] == 0 ) { for ( int j = i * 2 ; j <= MAX ; j += i ) { if ( sieve_Prime [ j ] == 0 ) { sieve_Prime [ j ] = 1 ; sieve_count [ i ] ++ ; } } } } } int main ( ) { form_sieve ( ) ; int n = 2 ; cout << " Count ▁ = ▁ " << ( sieve_count [ n ] + 1 ) << endl ; n = 3 ; cout << " Count ▁ = ▁ " << ( sieve_count [ n ] + 1 ) << endl ; return 0 ; }
How to access elements of a Square Matrix | C ++ Program to read a square matrix and print the elements on secondary diagonal ; Get the square matrix ; Display the matrix ; Print the elements on secondary diagonal ; check for elements on secondary diagonal
#include <bits/stdc++.h> NEW_LINE using namespace std ; int main ( ) { int matrix [ 5 ] [ 5 ] , row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } cout << " The ▁ matrix ▁ is STRNEWLINE " ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { cout << matrix [ row_index ] [ column_index ] << " ▁ " ; } cout << endl ; } cout << " Elements on Secondary diagonal : " for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) == size - 1 ) cout << matrix [ row_index ] [ column_index ] << " , ▁ " ; } } return 0 ; }
How to access elements of a Square Matrix | C ++ Program to read a square matrix and print the elements above secondary diagonal ; Get the square matrix ; Display the matrix ; Print the elements above secondary diagonal ; check for elements above secondary diagonal
#include <bits/stdc++.h> NEW_LINE using namespace std ; int main ( ) { int matrix [ 5 ] [ 5 ] , row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } cout << " The ▁ matrix ▁ is STRNEWLINE " ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { cout << matrix [ row_index ] [ column_index ] << " ▁ " ; } cout << endl ; } cout << " Elements above Secondary diagonal are : " ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) < size - 1 ) cout << matrix [ row_index ] [ column_index ] << " , ▁ " ; } } return 0 ; }
How to access elements of a Square Matrix | C ++ Program to read a square matrix and print the Corner Elements ; Get the square matrix ; Display the matrix ; Print the Corner elements ; check for corner elements
#include <bits/stdc++.h> NEW_LINE using namespace std ; int main ( ) { int matrix [ 5 ] [ 5 ] , row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } cout << " The ▁ matrix ▁ is " << endl ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { cout << " TABSYMBOL " << matrix [ row_index ] [ column_index ] ; } cout << endl ; } cout << " Corner Elements are : " ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index == 0 row_index == size - 1 ) && ( column_index == 0 column_index == size - 1 ) ) cout << matrix [ row_index ] [ column_index ] << " , " ; } } return 0 ; }
Find the largest good number in the divisors of given number N | CPP program to find the largest , good number in the divisors of given number N . ; function to return distinct prime factors ; to store distinct prime factors ; run a loop upto sqrt ( n ) ; place this prime factor in vector ; This condition is to handle the case when n is a prime number greater than 1 ; function that returns good number ; distinct prime factors ; to store answer ; product of all distinct prime factors is required answer ; Driver code ; function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < int > PrimeFactors ( int n ) { vector < int > v ; int x = n ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( x % i == 0 ) { v . push_back ( i ) ; while ( x % i == 0 ) x /= i ; } } if ( x > 1 ) v . push_back ( x ) ; return v ; } int GoodNumber ( int n ) { vector < int > v = PrimeFactors ( n ) ; int ans = 1 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) ans *= v [ i ] ; return ans ; } int main ( ) { int n = 12 ; cout << GoodNumber ( n ) ; return 0 ; }
Find Largest Special Prime which is less than or equal to a given number | CPP program to find the Largest Special Prime which is less than or equal to a given number ; Function to check whether the number is a special prime or not ; While number is not equal to zero ; If the number is not prime return false . ; Else remove the last digit by dividing the number by 10. ; If the number has become zero then the number is special prime , hence return true ; Function to find the Largest Special Prime which is less than or equal to a given number ; Initially all numbers are considered Primes . ; There is always an answer possible ; Checking if the number is a special prime or not ; If yes print the number and break the loop . ; Else decrement the number . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkSpecialPrime ( bool * sieve , int num ) { while ( num ) { if ( ! sieve [ num ] ) { return false ; } num /= 10 ; } return true ; } void findSpecialPrime ( int N ) { bool sieve [ N + 10 ] ; memset ( sieve , true , sizeof ( sieve ) ) ; sieve [ 0 ] = sieve [ 1 ] = false ; for ( long long i = 2 ; i <= N ; i ++ ) { if ( sieve [ i ] ) { for ( long long j = i * i ; j <= N ; j += i ) { sieve [ j ] = false ; } } } while ( true ) { if ( checkSpecialPrime ( sieve , N ) ) { cout << N << ' ' ; break ; } else N -- ; } } int main ( ) { findSpecialPrime ( 379 ) ; findSpecialPrime ( 100 ) ; return 0 ; }
Check if an integer can be expressed as a sum of two semi | CPP Code to check if an integer can be expressed as sum of two semi - primes ; Utility function to compute semi - primes in a range ; num /= j , ++ cnt ; Increment count of prime numbers ; If number is greater than 1 , add it to the count variable as it indicates the number remain is prime number ; if count is equal to '2' then number is semi - prime ; Utility function to check if a number sum of two semi - primes ; arr [ i ] is already a semi - prime if n - arr [ i ] is also a semi - prime then we a number can be expressed as sum of two semi - primes ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  1000000 NEW_LINE vector < int > arr ; bool sprime [ MAX ] ; void computeSemiPrime ( ) { memset ( sprime , false , sizeof ( sprime ) ) ; for ( int i = 2 ; i < MAX ; i ++ ) { int cnt = 0 ; int num = i ; for ( int j = 2 ; cnt < 2 && j * j <= num ; ++ j ) { while ( num % j == 0 ) { } } if ( num > 1 ) ++ cnt ; if ( cnt == 2 ) { sprime [ i ] = true ; arr . push_back ( i ) ; } } } bool checkSemiPrime ( int n ) { int i = 0 ; while ( arr [ i ] <= n / 2 ) { if ( sprime [ n - arr [ i ] ] ) { return true ; } i ++ ; } return false ; } int main ( ) { computeSemiPrime ( ) ; int n = 30 ; if ( checkSemiPrime ( n ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }
Check if a number is a Pythagorean Prime or not | CPP program to check if a number is Pythagorean prime or not ; Function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Driver Program ; Check if number is prime and of the form 4 * n + 1
#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 ; } int main ( ) { int n = 13 ; if ( isPrime ( n ) && ( n % 4 == 1 ) ) { cout << " YES " ; } else { cout << " NO " ; } return 0 ; }
Divide an isosceles triangle in two parts with ratio of areas as n : m | C ++ program , to find height h which divide isosceles triangle into ratio n : m ; Function to return the height ; type cast the n , m into float ; calculate the height for cut ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float heightCalculate ( int H , int n , int m ) { float N = n * 1.0 ; float M = m * 1.0 ; float h = H * sqrt ( N / ( N + M ) ) ; return h ; } int main ( ) { int H = 10 , n = 3 , m = 4 ; cout << heightCalculate ( H , n , m ) ; return 0 ; }
Check n ^ 2 | CPP program to find n ^ 2 - m ^ 2 is prime or not . ; Check a number is prime or not ; run a loop upto square of given number ; Check if n ^ 2 - m ^ 2 is prime ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isprime ( int x ) { for ( int i = 2 ; i * i <= x ; i ++ ) if ( x % i == 0 ) return false ; return true ; } bool isNSqMinusnMSqPrime ( int m , int n ) { if ( n - m == 1 and isprime ( m + n ) ) return true ; else return false ; } int main ( ) { int m = 13 , n = 16 ; if ( isNSqMinusnMSqPrime ( m , n ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }
Find ' N ' number of solutions with the given inequality equations | C ++ implementation of above approach ; Function to calculate all the solutions ; there is no solutions ; print first element as y - n + 1 ; print rest n - 1 elements as 1 ; Driver code ; initialize the number of elements and the value of x an y
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE void findsolution ( ll n , ll x , ll y ) { if ( ( y - n + 1 ) * ( y - n + 1 ) + n - 1 < x y < n ) { cout << " No ▁ solution " ; return ; } cout << y - n + 1 ; while ( n -- > 1 ) cout << endl << 1 ; } int main ( ) { ll n , x , y ; n = 5 , x = 15 , y = 15 ; findsolution ( n , x , y ) ; return 0 ; }
Number of different positions where a person can stand | C ++ implementation of above approach ; Function to find the position ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findPosition ( int n , int f , int b ) { return n - max ( f + 1 , n - b ) + 1 ; } int main ( ) { int n = 5 , f = 2 , b = 3 ; cout << findPosition ( n , f , b ) ; return 0 ; }
Program for n | CPP program to find the nth odd number ; Function to find the nth odd number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int nthOdd ( int n ) { return ( 2 * n - 1 ) ; } int main ( ) { int n = 10 ; cout << nthOdd ( n ) ; return 0 ; }
Program for n | CPP program to find the nth even number ; Function to find the nth even number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int nthEven ( int n ) { return ( 2 * n ) ; } int main ( ) { int n = 10 ; cout << nthEven ( n ) ; return 0 ; }
Program to find the Nth Harmonic Number | CPP program to find N - th Harmonic Number ; Function to find N - th Harmonic Number ; H1 = 1 ; loop to apply the forumula Hn = H1 + H2 + H3 ... + Hn - 1 + Hn - 1 + 1 / n ; Driver Code
#include <iostream> NEW_LINE using namespace std ; double nthHarmonic ( int N ) { float harmonic = 1.00 ; for ( int i = 2 ; i <= N ; i ++ ) { harmonic += ( float ) 1 / i ; } return harmonic ; } int main ( ) { int N = 8 ; cout << nthHarmonic ( N ) ; return 0 ; }
Program to find Nth term of series 0 , 7 , 18 , 33 , 51 , 75 , 102 , 133 , ... . . | C ++ program to find the N - th term of the series : 0 , 7 , 18 , 33 , 51 , 75 , 102 , ... . . ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 2 * pow ( n , 2 ) + n - 3 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }
Program to find Nth term of series 0 , 10 , 30 , 60 , 99 , 150 , 210 , 280. ... ... ... . | C ++ program to find the N - th term of the series : 0 , 10 , 30 , 60 , 99 , 150 , 210 , ... . . ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 5 * pow ( n , 2 ) - 5 * n ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }
Program to find Nth term of series 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . | C ++ program to find the N - th term of the series : 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 3 * pow ( n , 2 ) + n - 2 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }
Program to find Nth term of series 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . | CPP program to find the N - th term of the series : 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 2 * pow ( n , 2 ) + 4 * n - 2 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }
Program to find Nth term of series 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203 , ... . | CPP program to find the N - th term of the series : 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203. . ... ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 3 * pow ( n , 2 ) + 2 * n - 5 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }
Program to find Nth term of series 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147 , ... . . | C ++ program to find the N - th term of the series : 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147. . ... ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 2 * pow ( n , 2 ) + 3 * n - 5 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }
Program to find Nth term of series 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . | C ++ program to find the N - th term of the series : 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 4 * pow ( n , 2 ) - 3 * n + 2 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) << endl ; return 0 ; }
Find other two sides and angles of a right angle triangle | C ++ program to print all sides and angles of right angle triangle given one side ; Function to find angle A Angle in front of side a ; applied cosine rule ; convert into degrees ; Function to find angle B Angle in front of side b ; applied cosine rule ; convert into degrees and return ; Function to print all angles of the right angled triangle ; for calculate angle A ; for calculate angle B ; Function to find other two sides of the right angled triangle ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; Print angles of the triangle ; Driver Program
#include <bits/stdc++.h> NEW_LINE #include <cmath> NEW_LINE using namespace std ; #define PI  3.1415926535 NEW_LINE double findAnglesA ( double a , double b , double c ) { double A = acos ( ( b * b + c * c - a * a ) / ( 2 * b * c ) ) ; return A * 180 / PI ; } double findAnglesB ( double a , double b , double c ) { double B = acos ( ( a * a + c * c - b * b ) / ( 2 * a * c ) ) ; return B * 180 / PI ; } void printAngles ( int a , int b , int c ) { double x = ( double ) a ; double y = ( double ) b ; double z = ( double ) c ; double A = findAnglesA ( x , y , z ) ; double B = findAnglesB ( x , y , z ) ; cout << " Angles ▁ are ▁ A ▁ = ▁ " << A << " , ▁ B ▁ = ▁ " << B << " , ▁ C ▁ = ▁ " << 90 << endl ; } void printOtherSides ( int n ) { int b , c ; if ( n & 1 ) { if ( n == 1 ) cout << -1 << endl ; else { b = ( n * n - 1 ) / 2 ; c = ( n * n + 1 ) / 2 ; cout << " Side ▁ b ▁ = ▁ " << b << " , ▁ Side ▁ c ▁ = ▁ " << c << endl ; } } else { if ( n == 2 ) cout << -1 << endl ; else { b = n * n / 4 - 1 ; c = n * n / 4 + 1 ; cout << " Side ▁ b ▁ = ▁ " << b << " , ▁ Side ▁ c ▁ = ▁ " << c << endl ; } } printAngles ( n , b , c ) ; } int main ( ) { int a = 12 ; printOtherSides ( a ) ; return 0 ; }
Sum of the first N terms of the series 2 , 6 , 12 , 20 , 30. ... | C ++ program to find sum of first n terms ; Function to calculate the sum ; Driver code ; number of terms to be included in the sum ; find the Sn
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculateSum ( int n ) { return n * ( n + 1 ) / 2 + n * ( n + 1 ) * ( 2 * n + 1 ) / 6 ; } int main ( ) { int n = 3 ; cout << " Sum ▁ = ▁ " << calculateSum ( n ) ; return 0 ; }
Program to find the Nth term of the series 0 , 5 , 14 , 27 , 44 , ... ... . . | CPP program to find N - th term of the series : 0 , 5 , 14 , 27 , 44 . . . ; Calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 2 * pow ( n , 2 ) - n - 1 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) ; return 0 ; }
Program to find the Nth term of the series 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ... | CPP program to find the N - th term of the series : 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ... ; calculate Nth term of series ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int nthTerm ( int n ) { return 4 * pow ( n , 2 ) - 7 * n + 3 ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) ; return 0 ; }
Check whether a given Number is Power | C ++ program to find whether a number is power - isolated or not ; for 2 as prime factor ; for odd prime factor ; calculate product of powers and prime factors ; check result for power - isolation ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkIfPowerIsolated ( int num ) { int input = num ; int count = 0 ; int factor [ num + 1 ] = { 0 } ; if ( num % 2 == 0 ) { while ( num % 2 == 0 ) { ++ count ; num /= 2 ; } factor [ 2 ] = count ; } for ( int i = 3 ; i * i <= num ; i += 2 ) { count = 0 ; while ( num % i == 0 ) { ++ count ; num /= i ; } if ( count > 0 ) factor [ i ] = count ; } if ( num > 1 ) factor [ num ] = 1 ; int product = 1 ; for ( int i = 0 ; i < num + 1 ; i ++ ) { if ( factor [ i ] > 0 ) product = product * factor [ i ] * i ; } if ( product == input ) cout << " Power - isolated ▁ Integer STRNEWLINE " ; else cout << " Not ▁ a ▁ Power - isolated ▁ Integer STRNEWLINE " ; } int main ( ) { checkIfPowerIsolated ( 12 ) ; checkIfPowerIsolated ( 18 ) ; checkIfPowerIsolated ( 35 ) ; return 0 ; }
Program to find the Nth term of the series 3 , 7 , 13 , 21 , 31. ... . | CPP program to find the Nth term of given series . ; Function to calculate sum ; Return Nth term ; driver code ; declaration of number of terms ; Get the Nth term
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; long long int getNthTerm ( long long int N ) { return ( pow ( N , 2 ) + N + 1 ) ; } int main ( ) { long long int N = 11 ; cout << getNthTerm ( N ) ; return 0 ; }
Sum of the numbers upto N that are divisible by 2 or 5 | C ++ implementation of above approach ; Function to find the sum ; sum2 is sum of numbers divisible by 2 ; sum5 is sum of number divisible by 5 ; sum10 of numbers divisible by 2 and 5 ; Driver code
#include <bits/stdc++.h> NEW_LINE #define ll  long long int NEW_LINE using namespace std ; ll findSum ( int n ) { ll sum2 , sum5 , sum10 ; sum2 = ( ( n / 2 ) * ( 4 + ( n / 2 - 1 ) * 2 ) ) / 2 ; sum5 = ( ( n / 5 ) * ( 10 + ( n / 5 - 1 ) * 5 ) ) / 2 ; sum10 = ( ( n / 10 ) * ( 20 + ( n / 10 - 1 ) * 10 ) ) / 2 ; return sum2 + sum5 - sum10 ; } int main ( ) { int n = 5 ; cout << findSum ( n ) << endl ; return 0 ; }