codeparrot/xlcost-text-to-code huggingface dataset:
Count of all values of N in [ L , R ] such that count of primes upto N is also prime | C ++ program for the above approach ; Function to count the number of crazy primes in the given range [ L , R ] ; Stores all primes ; Stores count of primes ; Stores if frequency of primes is a prime or not upto each index ; Sieve of Eratosthenes ; Count primes ; If i is a prime ; Stores frequency of primes ; If the frequency of primes is a prime ; Increase count of required numbers ; Return the required count ; Driver Code ; Given Range ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int count_crazy_primes ( int L , int R ) { int prime [ R + 1 ] = { 0 } ; int countPrime [ R + 1 ] = { 0 } ; int freqPrime [ R + 1 ] = { 0 } ; prime [ 0 ] = prime [ 1 ] = 1 ; for ( int p = 2 ; p * p <= R ; p ++ ) { if ( prime [ p ] == 0 ) { for ( int i = p * p ; i <= R ; i += p ) prime [ i ] = 1 ; } } for ( int i = 1 ; i <= R ; i ++ ) { countPrime [ i ] = countPrime [ i - 1 ] ; if ( ! prime [ i ] ) { countPrime [ i ] ++ ; } } for ( int i = 1 ; i <= R ; i ++ ) { freqPrime [ i ] = freqPrime [ i - 1 ] ; if ( ! prime [ countPrime [ i ] ] ) { freqPrime [ i ] ++ ; } } return ( freqPrime [ R ] - freqPrime [ L - 1 ] ) ; } int main ( ) { int L = 4 , R = 12 ; cout << count_crazy_primes ( L , R ) ; return 0 ; }
Largest N digit number in Base B | C ++ program for the approach ; Function to print the largest N - digit numbers of base b ; Find the largest N digit number in base b using the formula B ^ N - 1 ; Print the largest number ; Driver Code ; Given Number and Base ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findNumbers ( int n , int b ) { int largest = pow ( b , n ) - 1 ; cout << largest << endl ; } int main ( ) { int N = 2 , B = 5 ; findNumbers ( N , B ) ; return 0 ; }
Generate an Array such with elements maximized through swapping bits | C ++ implementation to find maximum sequence by swapping bits ; Function to generate the maximized array elements ; Traverse the array ; Iterate to count set and unset bits ; Count of unset bits ; Count of set bits ; Bitwise right shift ; Shifting all 1 ' s ▁ to ▁ MSB ▁ ▁ and ▁ 0' s to LSB ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void maximizedArray ( int arr [ ] , int N ) { int num , i = 0 ; while ( N -- ) { num = arr [ i ] ; int one = 0 ; int zero = 0 ; while ( num ) { if ( num % 2 == 0 ) { zero ++ ; } else { one ++ ; } num = num >> 1 ; } for ( int j = zero ; j < ( one + zero ) ; j ++ ) { num += ( 1 << j ) ; } cout << num ; i ++ ; if ( N > 0 ) cout << " , ▁ " ; } } int main ( ) { int arr [ ] = { 8 , 15 , 9 , 10 , 14 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maximizedArray ( arr , N ) ; return 0 ; }
Find the ratio of LCM to GCD of a given Array | C ++ Program to implement above approach ; Function to calculate and return GCD of the given array ; Initialise GCD ; Once GCD is 1 , it will always be 1 with all other elements ; Return GCD ; Function to calculate and return LCM of the given array ; Initialise LCM ; LCM of two numbers is evaluated as [ ( a * b ) / gcd ( a , b ) ] ; Return LCM ; Function to print the ratio of LCM to GCD of the given array ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findGCD ( int arr [ ] , int n ) { int gcd = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { gcd = __gcd ( arr [ i ] , gcd ) ; if ( gcd == 1 ) { return 1 ; } } return gcd ; } int findLCM ( int arr [ ] , int n ) { int lcm = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { lcm = ( ( ( arr [ i ] * lcm ) ) / ( __gcd ( arr [ i ] , lcm ) ) ) ; } return lcm ; } void findRatio ( int arr [ ] , int n ) { int gcd = findGCD ( arr , n ) ; int lcm = findLCM ( arr , n ) ; cout << lcm / gcd << " : " << 1 << endl ; } int main ( ) { int arr [ ] = { 6 , 12 , 36 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findRatio ( arr , N ) ; return 0 ; }
Minimum operations required to make all Array elements divisible by K | C ++ implementation to find the Minimum number of moves required to update the array such that each of its element is divisible by K ; Function to find the Minimum number of moves required to update the array such that each of its element is divisible by K ; Initialize Map data structure ; Iterate for all the elements of the array ; Calculate the value to be added ; Check if the value equals to 0 then simply continue ; Check if the value to be added is present in the map ; Update the answer ; Print the required result We need to add 1 to maxX because we cant ignore the first move where initially X = 0 and we need to increase it by 1 to make some changes in array ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void compute ( int a [ ] , int N , int K ) { map < long , long > eqVal ; long maxX = 0 ; for ( int i = 0 ; i < N ; i ++ ) { long val = a [ i ] % K ; val = ( val == 0 ? 0 : K - val ) ; if ( val == 0 ) continue ; if ( eqVal . find ( val ) != eqVal . end ( ) ) { long numVal = eqVal [ val ] ; maxX = max ( maxX , val + ( K * numVal ) ) ; eqVal [ val ] ++ ; } else { eqVal [ val ] ++ ; maxX = max ( maxX , val ) ; } } cout << ( maxX == 0 ? 0 : maxX + 1 ) << endl ; } int main ( ) { int K = 3 ; int a [ ] = { 1 , 2 , 2 , 18 } ; int N = sizeof ( a ) / sizeof ( a [ 0 ] ) ; compute ( a , N , K ) ; return 0 ; }
Array sum after replacing all occurrences of X by Y for Q queries | C ++ implementation to find the sum of the array for the given Q queries ; Function that print the sum of the array for Q queries ; Stores the frequencies of array elements ; Calculate the sum of the initial array and store the frequency of each element in map ; Iterate for all the queries ; Store query values ; Decrement the sum accordingly ; Increment the sum accordingly ; Set count of Y [ i ] ; Reset count of X [ i ] ; Print the sum ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void sumOfTheArrayForQuery ( int * A , int N , int * X , int * Y , int Q ) { int sum = 0 ; unordered_map < int , int > count ; for ( int i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; count [ A [ i ] ] ++ ; } for ( int i = 0 ; i < Q ; i ++ ) { int x = X [ i ] , y = Y [ i ] ; sum -= count [ X [ i ] ] * X [ i ] ; sum += count [ X [ i ] ] * Y [ i ] ; count [ Y [ i ] ] += count [ X [ i ] ] ; count [ X [ i ] ] = 0 ; cout << sum << " ▁ " ; } } int main ( ) { int arr [ ] = { 1 , 2 , 1 , 3 , 2 } ; int X [ ] = { 2 , 3 , 5 } ; int Y [ ] = { 3 , 1 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int Q = sizeof ( X ) / sizeof ( X [ 0 ] ) ; sumOfTheArrayForQuery ( arr , N , X , Y , Q ) ; return 0 ; }
Maximum OR value of a pair in an Array | Set 2 | C ++ implementation of the approach above ; Function to return the maximum bitwise OR for any pair of the given array in O ( n ) time complexity . ; Find the maximum element in the array ; Stores the maximum OR value ; Traverse the array and perform Bitwise OR between every array element with the maximum element ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxOR ( int arr [ ] , int n ) { int max_value = * max_element ( arr , arr + n ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans = max ( ans , ( max_value arr [ i ] ) ) ; } return ans ; } int main ( ) { int arr [ ] = { 3 , 6 , 8 , 16 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxOR ( arr , n ) ; return 0 ; }
Count of elements on the left which are divisible by current element | Set 2 | C ++ implementation of the approach ; Utility function to print the elements of the array ; Function to increment the count for each factor of given val ; Function to generate and print the required array ; Find max element of array ; Create count array of maxi size ; For every element of the array ; Count [ A [ i ] ] denotes how many previous elements are there whose factor is the current element . ; Increment in count array for factors of A [ i ] ; Print the generated array ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } void IncrementFactors ( int count [ ] , int val ) { for ( int i = 1 ; i * i <= val ; i ++ ) { if ( val % i == 0 ) { if ( i == val / i ) { count [ i ] ++ ; } else { count [ i ] ++ ; count [ val / i ] ++ ; } } } } void generateArr ( int A [ ] , int n ) { int B [ n ] ; int maxi = * max_element ( A , A + n ) ; int count [ maxi + 1 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { B [ i ] = count [ A [ i ] ] ; IncrementFactors ( count , A [ i ] ) ; } printArr ( B , n ) ; } int main ( ) { int arr [ ] = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; generateArr ( arr , n ) ; return 0 ; }
Minimum changes required to make all Array elements Prime | C ++ Program to implement the above approach ; Function to generate all primes ; If p is a prime ; Mark all its multiples as non - prime ; Store all prime numbers ; Return the list of primes ; Function to calculate the minimum increments to convert every array elements to a prime ; Extract maximum element of the given array ; Extract the index which has the next greater prime ; Store the difference between the prime and the array element ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < int > SieveOfEratosthenes ( int n ) { bool prime [ 2 * n + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= 2 * n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= 2 * n ; i += p ) prime [ i ] = false ; } } vector < int > primes ; for ( int p = 2 ; p <= 2 * n ; p ++ ) if ( prime [ p ] ) primes . push_back ( p ) ; return primes ; } int minChanges ( vector < int > arr ) { int n = arr . size ( ) ; int ans = 0 ; int maxi = * max_element ( arr . begin ( ) , arr . end ( ) ) ; vector < int > primes = SieveOfEratosthenes ( maxi ) ; for ( int i = 0 ; i < n ; i ++ ) { int x = lower_bound ( primes . begin ( ) , primes . end ( ) , arr [ i ] ) - primes . begin ( ) ; int minm = abs ( primes [ x ] - arr [ i ] ) ; if ( x > 1 ) { minm = min ( minm , abs ( primes [ x - 1 ] - arr [ i ] ) ) ; } ans += minm ; } return ans ; } int main ( ) { vector < int > arr = { 4 , 25 , 13 , 6 , 20 } ; cout << minChanges ( arr ) ; return 0 ; }
Sum of multiples of Array elements within a given range [ L , R ] | C ++ program for the above approach ; Function to find the sum of all multiples of N up to K ; Calculate the sum ; Return the sum ; Function to find the total sum ; If L is divisible by a [ i ] ; Otherwise ; Return the final sum ; Driver Code ; Given array arr [ ] ; Given range ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calcSum ( int k , int n ) { int value = ( k * n * ( n + 1 ) ) / 2 ; return value ; } int findSum ( int * a , int n , int L , int R ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( L % a [ i ] == 0 && L != 0 ) { sum += calcSum ( a [ i ] , R / a [ i ] ) - calcSum ( a [ i ] , ( L - 1 ) / a [ i ] ) ; } else { sum += calcSum ( a [ i ] , R / a [ i ] ) - calcSum ( a [ i ] , L / a [ i ] ) ; } } return sum ; } int main ( ) { int arr [ ] = { 2 , 7 , 3 , 8 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int L = 7 ; int R = 20 ; cout << findSum ( arr , N , L , R ) ; return 0 ; }
Count all prime numbers in a given range whose sum of digits is also prime | C ++ program for the above approach ; Create an array for storing primes ; Create a prefix array that will contain whether sum is prime or not ; Function to find primes in the range and check whether the sum of digits of a prime number is prime or not ; Initialise Prime array arr [ ] ; Since 0 and 1 are not prime numbers we mark them as '0' ; Using Sieve Of Eratosthenes ; if the number is prime ; Mark all the multiples of i starting from square of i with '0' ie . composite ; '0' represents not prime ; Initialise a sum variable as 0 ; Check if the number is prime ; A temporary variable to store the number ; Loop to calculate the sum of digits ; Check if the sum of prime number is prime ; if prime mark 1 ; If not prime mark 0 ; computing prefix array ; Function to count the prime numbers in the range [ L , R ] ; Function Call to find primes ; Print the result ; Driver Code ; Input range ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxN = 1000000 ; int arr [ 1000001 ] ; int prefix [ 1000001 ] ; void findPrimes ( ) { for ( int i = 1 ; i <= maxN ; i ++ ) arr [ i ] = 1 ; arr [ 0 ] = 0 , arr [ 1 ] = 0 ; for ( int i = 2 ; i * i <= maxN ; i ++ ) { if ( arr [ i ] == 1 ) { for ( int j = i * i ; j <= maxN ; j += i ) { arr [ j ] = 0 ; } } } int sum = 0 ; prefix [ 0 ] = 0 ; for ( int i = 1 ; i <= maxN ; i ++ ) { if ( arr [ i ] == 1 ) { int temp = i ; sum = 0 ; while ( temp > 0 ) { int x = temp % 10 ; sum += x ; temp = temp / 10 ; if ( arr [ sum ] == 1 ) { prefix [ i ] = 1 ; } else { prefix [ i ] = 0 ; } } } } for ( int i = 1 ; i <= maxN ; i ++ ) { prefix [ i ] += prefix [ i - 1 ] ; } } void countNumbersInRange ( int l , int r ) { findPrimes ( ) ; int result = prefix [ r ] - prefix [ l - 1 ] ; cout << result << endl ; } int main ( ) { int l , r ; l = 5 , r = 20 ; countNumbersInRange ( l , r ) ; return 0 ; }
Find the concentration of a solution using given Mass and Volume | C ++ program to find concentration of a solution using given Mass and Volume ; Function to calculate concentration from the given mass of solute and volume of a solution ; Driver Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; double get_concentration ( double mass , double volume ) { if ( volume == 0 ) return -1 ; else return ( mass / volume ) * 1000 ; } int main ( ) { double mass , volume ; mass = 100.00 ; volume = 500.00 ; cout << get_concentration ( mass , volume ) ; return 0 ; }
Practical Numbers | C ++ program to check if a number is Practical or not . ; Returns true if there is a subset of set [ ] with sun equal to given sum ; The value of subset [ i ] [ j ] will be true if there is a subset of set [ 0. . j - 1 ] with sum equal to i ; If sum is 0 , then answer is true ; If sum is not 0 and set is empty , then answer is false ; Fill the subset table in bottom up manner ; Function to store divisors of N in a vector ; Find all divisors which divides ' num ' ; if ' i ' is divisor of ' n ' ; if both divisors are same then store it once else store both divisors ; Returns true if num is Practical ; vector to store all divisors of N ; to check all numbers from 1 to < N ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isSubsetSum ( vector < int > & set , int n , int sum ) { bool subset [ n + 1 ] [ sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( int i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ; } } return subset [ n ] [ sum ] ; } void storeDivisors ( int n , vector < int > & div ) { for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) div . push_back ( i ) ; else { div . push_back ( i ) ; div . push_back ( n / i ) ; } } } } bool isPractical ( int N ) { vector < int > div ; storeDivisors ( N , div ) ; for ( int i = 1 ; i < N ; i ++ ) { if ( ! isSubsetSum ( div , div . size ( ) , i ) ) return false ; } return true ; } int main ( ) { int N = 18 ; isPractical ( N ) ? cout << " Yes " : cout << " No " ; return 0 ; }
Super Niven Numbers | C ++ implementation to check if a number is Super Niven Number or not . ; Checks if sums of all subsets of digits array divides the number N ; to calculate length of array arr ; There are totoal 2 ^ n subsets ; Consider all numbers from 0 to 2 ^ n - 1 ; Consider binary representation of current i to decide which elements to pick . ; check sum of picked elements . ; Function to check if a number is a super - niven number ; to stor digits of N ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDivBySubsetSums ( vector < int > arr , int num ) { int n = arr . size ( ) ; long long total = 1 << n ; for ( long long i = 0 ; i < total ; i ++ ) { long long sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) if ( i & ( 1 << j ) ) sum += arr [ j ] ; if ( sum != 0 && num % sum != 0 ) return false ; } return true ; } bool isSuperNivenNum ( int n ) { int temp = n ; vector < int > digits ; while ( n != 0 ) { int digit = n % 10 ; digits . push_back ( digit ) ; n = n / 10 ; } return isDivBySubsetSums ( digits , temp ) ; } int main ( ) { int n = 500 ; if ( isSuperNivenNum ( n ) ) cout << " yes " ; else cout << " No " ; return 0 ; }
Highly Composite Numbers | C ++ implementation for checking Highly Composite Number ; Function to count the number of divisors of the N ; sieve method for prime calculation ; Traversing through all prime numbers ; calculate number of divisor with formula total div = ( p1 + 1 ) * ( p2 + 1 ) * ... . . * ( pn + 1 ) where n = ( a1 ^ p1 ) * ( a2 ^ p2 ) . ... * ( an ^ pn ) ai being prime divisor for n and pi are their respective power in factorization ; Function to check if a number is a highly composite number ; count number of factors of N ; loop to count number of factors of every number less than N ; If any number less than N has more factors than N , then return false ; Driver code ; Given Number N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int divCount ( int n ) { bool hash [ n + 1 ] ; memset ( hash , true , sizeof ( hash ) ) ; for ( int p = 2 ; p * p < n ; p ++ ) if ( hash [ p ] == true ) for ( int i = p * 2 ; i < n ; i += p ) hash [ i ] = false ; int total = 1 ; for ( int p = 2 ; p <= n ; p ++ ) { if ( hash [ p ] ) { int count = 0 ; if ( n % p == 0 ) { while ( n % p == 0 ) { n = n / p ; count ++ ; } total = total * ( count + 1 ) ; } } } return total ; } bool isHighlyCompositeNumber ( int N ) { int NdivCount = divCount ( N ) ; for ( int i = 1 ; i < N ; i ++ ) { int idivCount = divCount ( i ) ; if ( idivCount >= NdivCount ) return false ; } return true ; } int main ( ) { int N = 12 ; if ( isHighlyCompositeNumber ( N ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Pentacontahenagon Number | C ++ program for the above approach ; Function to find the N - th Pentacontahenagon Number ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int PentacontahenagonNum ( int N ) { return ( 49 * N * N - 47 * N ) / 2 ; } int main ( ) { int N = 3 ; cout << "3rd ▁ Pentacontahenagon ▁ Number ▁ is ▁ " << PentacontahenagonNum ( N ) ; return 0 ; }
Saint | C ++ implementation to check if N is a Saint - Exupery number ; Function to check if a number is a Saint - Exupery number ; Considering triplets in sorted order . The value of first element in sorted triplet can be at - most n / 3. ; The value of second element must be less than equal to n / 2 ; Driver Code ; Given Number N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isSaintExuperyNum ( int n ) { for ( int i = 1 ; i <= n / 3 ; i ++ ) { for ( int j = i + 1 ; j <= n / 2 ; j ++ ) { int k = n / i / j ; if ( i * i + j * j == k * k ) { if ( i * j * k == n ) return true ; ; } } } return false ; } int main ( ) { int N = 60 ; if ( isSaintExuperyNum ( N ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Repdigit Numbers | C ++ implementation to check if a number is Repdigit ; Function to check if a number is a Repdigit number ; To store previous digit ( Assigning initial value which is less than any digit ) ; Traverse all digits from right to left and check if any digit is smaller than previous . ; Driver code
#include <iostream> NEW_LINE using namespace std ; bool isRepdigit ( int num , int b ) { int prev = -1 ; while ( num ) { int digit = num % b ; num /= b ; if ( prev != -1 && digit != prev ) return false ; prev = digit ; } return true ; } int main ( ) { int num = 2000 , base = 7 ; isRepdigit ( num , base ) ? cout << " Yes " : cout << " No " ; return 0 ; }
Enlightened Numbers | C ++ implementation of the above approach ; Function to check if N is a Composite Number ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to return concatenation of distinct prime factors of a given number n ; Handle prime factor 2 explicitly so that can optimally handle other prime factors . ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number greater than 2 ; Function to check if a number is is an enlightened number ; Number should not be prime ; Converting N to string ; Function call ; Driver code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; bool isComposite ( int n ) { if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } int concatenatePrimeFactors ( int n ) { char concatenate ; if ( n % 2 == 0 ) { concatenate += char ( 2 ) ; while ( n % 2 == 0 ) n = n / 2 ; } for ( int i = 3 ; i <= sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { concatenate += i ; while ( n % i == 0 ) n = n / i ; } } if ( n > 2 ) concatenate += n ; return concatenate ; } bool isEnlightened ( int N ) { if ( ! isComposite ( N ) ) return false ; char num = char ( N ) ; char prefixConc = concatenatePrimeFactors ( N ) ; return int ( prefixConc ) ; } int main ( ) { int n = 250 ; if ( isEnlightened ( n ) ) cout << " Yes " ; else cout << " No " ; }
Second Pentagonal 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 * ( 3 * n + 1 ) / 2 << endl ; } int main ( ) { int N = 4 ; findNthTerm ( N ) ; return 0 ; }
Idoneal Numbers | C ++ implementation for the above approach ; Function to check if number is an Idoneal numbers ; iterate for all triples pairs ( a , b , c ) ; if the condition is satisfied ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isIdoneal ( int n ) { for ( int a = 1 ; a <= n ; a ++ ) { for ( int b = a + 1 ; b <= n ; b ++ ) { for ( int c = b + 1 ; c <= n ; c ++ ) { if ( a * b + b * c + c * a == n ) return false ; } } } return true ; } int main ( ) { int N = 10 ; if ( isIdoneal ( N ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Lynch | C ++ implementation for the above approach ; Function to check the divisibility of the number by its digit . ; If the digit divides the number then return true else return false . ; Function to check if all digits of n divide it or not ; Taking the digit of the number into digit var . ; Function to check if N has all distinct digits ; Create an array of size 10 and initialize all elements as false . This array is used to check if a digit is already seen or not . ; Traverse through all digits of given number ; Find the last digit ; If digit is already seen , return false ; Mark this digit as seen ; REmove the last digit from number ; Function to check Lynch - Bell numbers ; Driver Code ; Given Number N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkDivisibility ( int n , int digit ) { return ( digit != 0 && n % digit == 0 ) ; } bool isAllDigitsDivide ( int n ) { int temp = n ; while ( temp > 0 ) { int digit = temp % 10 ; if ( ! ( checkDivisibility ( n , digit ) ) ) return false ; temp /= 10 ; } return true ; } bool isAllDigitsDistinct ( int n ) { bool arr [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) arr [ i ] = false ; while ( n > 0 ) { int digit = n % 10 ; if ( arr [ digit ] ) return false ; arr [ digit ] = true ; n = n / 10 ; } return true ; } bool isLynchBell ( int n ) { return isAllDigitsDivide ( n ) && isAllDigitsDistinct ( n ) ; } int main ( ) { int N = 12 ; if ( isLynchBell ( N ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }