codeparrot/xlcost-text-to-code huggingface dataset:
Count of elements not divisible by any other elements of Array | C ++ program for the above approach ; Function to count the number of elements of array which are not divisible by any other element in the array arr [ ] ; Iterate over the array ; Check if the element is itself or not ; Check for divisibility ; Return the final result ; Driver Code ; Given array ; Function Call
#include <bits/stdc++.h> NEW_LINE #define ll  long long int NEW_LINE using namespace std ; int count ( int a [ ] , int n ) { int countElements = 0 ; for ( int i = 0 ; i < n ; i ++ ) { bool flag = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) continue ; if ( a [ i ] % a [ j ] == 0 ) { flag = false ; break ; } } if ( flag == true ) ++ countElements ; } return countElements ; } int main ( ) { int arr [ ] = { 86 , 45 , 18 , 4 , 8 , 28 , 19 , 33 , 2 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << count ( arr , n ) ; return 0 ; }
Smallest N digit number divisible by N | C ++ program for the above approach ; Function to find the smallest N - digit number divisible by N ; Return the smallest N - digit number calculated using above formula ; Driver Code ; Given N ; Function Call
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int smallestNumber ( int N ) { return N * ceil ( pow ( 10 , ( N - 1 ) ) / N ) ; } int main ( ) { int N = 2 ; cout << smallestNumber ( N ) ; return 0 ; }
Count pairs in an array containing at least one even value | C ++ implementation to count pairs in an array such that each pair contains at least one even element ; Function to count the pairs in the array such as there is at least one even element in each pair ; Generate all possible pairs and increment then count if the condition is satisfied ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int CountPairs ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] % 2 == 0 arr [ j ] % 2 == 0 ) count ++ ; } } return count ; } int main ( ) { int arr [ ] = { 8 , 2 , 3 , 1 , 4 , 2 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << ( CountPairs ( arr , n ) ) ; }
Count pairs in an array containing at least one even value | C ++ implementation to Count pairs in an array such that each pair contains at least one even element ; Function to count the pairs in the array such as there is at least one even element in each pair ; Store count of even and odd elements ; Check element is even or odd ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int CountPairs ( int arr [ ] , int n ) { int even = 0 , odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } return ( even * ( even - 1 ) ) / 2 + ( even * odd ) ; } int main ( ) { int arr [ ] = { 8 , 2 , 3 , 1 , 4 , 2 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << CountPairs ( arr , n ) ; }
Giuga Numbers | C ++ program for the above approach ; Function to check if n is a composite number ; Corner cases ; This is checked to skip middle 5 numbers ; Function to check if N is a Giuga Number ; N should be composite to be a Giuga Number ; Print the number of 2 s that divide n ; N must be odd at this point . So we can skip one element ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number > 2 ; Driver Code ; Given Number N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isComposite ( int n ) { if ( n <= 1 ) return false ; 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 ; } bool isGiugaNum ( int n ) { if ( ! ( isComposite ( n ) ) ) return false ; int N = n ; while ( n % 2 == 0 ) { if ( ( N / 2 - 1 ) % 2 != 0 ) return false ; n = n / 2 ; } for ( int i = 3 ; i <= sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { if ( ( N / i - 1 ) % i != 0 ) return false ; n = n / i ; } } if ( n > 2 ) if ( ( N / n - 1 ) % n != 0 ) return false ; return true ; } int main ( ) { int N = 30 ; if ( isGiugaNum ( N ) ) cout << " Yes " ; else cout << " No " ; }
Droll Numbers | C ++ program for the above approach ; Function to check droll numbers ; To store sum of even prime factors ; To store sum of odd prime factors ; Add the number of 2 s that divide n in sum_even ; 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 ; Condition to check droll number ; Driver Code ; Given Number N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDroll ( int n ) { if ( n == 1 ) return false ; int sum_even = 0 ; int sum_odd = 0 ; while ( n % 2 == 0 ) { sum_even += 2 ; n = n / 2 ; } for ( int i = 3 ; i <= sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { sum_odd += i ; n = n / i ; } } if ( n > 2 ) sum_odd += n ; return sum_even == sum_odd ; } int main ( ) { int N = 72 ; if ( isDroll ( N ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Count all pairs of divisors of a number N whose sum is coprime with N | C ++ program to count all pairs of divisors such that their sum is coprime with N ; Function to calculate GCD ; Function to count all valid pairs ; Initialize count ; Check if sum of pair and n are coprime ; Return the result ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int gcd ( int a , int b ) { if ( b == 0 ) return a ; return ( gcd ( b , a % b ) ) ; } int CountPairs ( int n ) { int cnt = 0 ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { int div1 = i ; int div2 = n / i ; int sum = div1 + div2 ; if ( gcd ( sum , n ) == 1 ) cnt += 1 ; } } return cnt ; } int main ( ) { int n = 24 ; cout << CountPairs ( n ) << endl ; return 0 ; }
Check if A can be converted to B by reducing with a Prime number | C ++ implementation to find if it is possible to make a equal to b ; Function to find if it is possible to make A equal to B ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPossible ( int A , int B ) { return ( A - B > 1 ) ; } int main ( ) { int A = 10 , B = 4 ; if ( isPossible ( A , B ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Maximize sum of minimum difference of divisors of nodes in N | C ++ program to maximize the sum of minimum difference of divisors of nodes in an n - ary tree ; Array to store the result at each node ; Function to get minimum difference between the divisors of a number ; Iterate from square root of N to N ; return absolute difference ; DFS function to calculate the maximum sum ; Store the min difference ; Add the maximum of all children to sub [ u ] ; Return maximum sum of node ' u ' to its parent ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sub [ 100005 ] ; int minDivisorDifference ( int n ) { int num1 ; int num2 ; for ( int i = sqrt ( n ) ; i <= n ; i ++ ) { if ( n % i == 0 ) { num1 = i ; num2 = n / i ; break ; } } return abs ( num1 - num2 ) ; } int dfs ( vector < int > g [ ] , int u , int par ) { sub [ u ] = minDivisorDifference ( u ) ; int mx = 0 ; for ( auto c : g [ u ] ) { if ( c != par ) { int ans = dfs ( g , c , u ) ; mx = max ( mx , ans ) ; } } sub [ u ] += mx ; return sub [ u ] ; } int main ( ) { vector < int > g [ 100005 ] ; int edges = 6 ; g [ 18 ] . push_back ( 7 ) ; g [ 7 ] . push_back ( 18 ) ; g [ 18 ] . push_back ( 15 ) ; g [ 15 ] . push_back ( 18 ) ; g [ 15 ] . push_back ( 2 ) ; g [ 2 ] . push_back ( 15 ) ; g [ 7 ] . push_back ( 4 ) ; g [ 4 ] . push_back ( 7 ) ; g [ 7 ] . push_back ( 12 ) ; g [ 12 ] . push_back ( 7 ) ; g [ 12 ] . push_back ( 9 ) ; g [ 9 ] . push_back ( 12 ) ; int root = 18 ; cout << dfs ( g , root , -1 ) ; }
Program to check if N is a Centered Cubic Number | C ++ program to check if N is a centered cubic number ; Function to check if the number N is a centered cubic number ; Iterating from 1 ; Infinite loop ; Finding ith_term ; Checking if the number N is a Centered cube number ; If ith_term > N then N is not a Centered cube number ; Incrementing i ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isCenteredcube ( int N ) { int i = 1 ; while ( true ) { int ith_term = ( 2 * i + 1 ) * ( i * i + i + 1 ) ; if ( ith_term == N ) { return true ; } if ( ith_term > N ) { return false ; } i ++ ; } } int main ( ) { int N = 9 ; if ( isCenteredcube ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Product of N terms of a given Geometric series | C ++ program for the above approach ; Function to calculate product of geometric series ; Initialise final product with 1 ; Multiply product with each term stored in a ; Return the final product ; Driver Code ; Given first term and common ratio ; Number of terms ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; float productOfGP ( float a , float r , int n ) { float product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { product = product * a ; a = a * r ; } return product ; } int main ( ) { float a = 1 , r = 2 ; int N = 4 ; cout << productOfGP ( a , r , N ) ; }
Sum of given N fractions in reduced form | C ++ program for the above approach ; Function to find GCD of a & b using Euclid Lemma ; Base Case ; Function to find the LCM of all elements in arr [ ] ; Initialize result ; Iterate arr [ ] to find LCM ; Return the final LCM ; Function to find the sum of N fraction in reduced form ; To store the sum of all final numerators ; Find the LCM of all denominator ; Find the sum of all N numerators & denominators ; Add each fraction one by one ; Find GCD of final numerator and denominator ; Convert into reduced form by dividing from GCD ; Print the final fraction ; Driven Code ; Given N ; Given Numerator ; Given Denominator ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int gcd ( int a , int b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } int findlcm ( int arr [ ] , int n ) { int ans = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { ans = ( ( ( arr [ i ] * ans ) ) / ( gcd ( arr [ i ] , ans ) ) ) ; } return ans ; } void addReduce ( int n , int num [ ] , int den [ ] ) { int final_numerator = 0 ; int final_denominator = findlcm ( den , n ) ; for ( int i = 0 ; i < n ; i ++ ) { final_numerator = final_numerator + ( num [ i ] ) * ( final_denominator / den [ i ] ) ; } int GCD = gcd ( final_numerator , final_denominator ) ; final_numerator /= GCD ; final_denominator /= GCD ; cout << final_numerator << " / " << final_denominator << endl ; } int main ( ) { int N = 3 ; int arr1 [ ] = { 1 , 2 , 5 } ; int arr2 [ ] = { 2 , 1 , 6 } ; addReduce ( N , arr1 , arr2 ) ; return 0 ; }
Minimum LCM of all pairs in a given array | C ++ program to find minimum possible lcm from any pair ; function to compute GCD of two numbers ; function that return minimum possible lcm from any pair ; fix the ith element and iterate over all the array to find minimum LCM ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } int minLCM ( int arr [ ] , int n ) { int ans = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int g = gcd ( arr [ i ] , arr [ j ] ) ; int lcm = arr [ i ] / g * arr [ j ] ; ans = min ( ans , lcm ) ; } } return ans ; } int main ( ) { int arr [ ] = { 2 , 4 , 3 , 6 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minLCM ( arr , n ) << endl ; return 0 ; }
Find two numbers whose difference of fourth power is equal to N | C ++ implementation to find the values of x and y for the given equation with integer N ; Function which find required x & y ; Upper limit of x & y , if such x & y exists ; num1 stores x ^ 4 ; num2 stores y ^ 4 ; If condition is satisfied the print and return ; If no such pair exists ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void solve ( int n ) { int upper_limit = ceil ( pow ( n , 1.0 / 4 ) ) ; for ( int x = 0 ; x <= upper_limit ; x ++ ) { for ( int y = 0 ; y <= upper_limit ; y ++ ) { int num1 = x * x * x * x ; int num2 = y * y * y * y ; if ( num1 - num2 == n ) { cout << " x ▁ = ▁ " << x << " , ▁ y ▁ = ▁ " << y ; return ; } } } cout << -1 << endl ; } int main ( ) { int n = 15 ; solve ( n ) ; return 0 ; }
Check if count of even divisors of N is equal to count of odd divisors | C ++ program for the above approach ; Function to check if count of even and odd divisors are equal ; To store the count of even factors and odd factors ; Loop till [ 1 , sqrt ( N ) ] ; If divisors are equal add only one ; Check for even divisor ; Odd divisor ; Check for both divisor i . e . , i and N / i ; Check if i is odd or even ; Check if N / i is odd or even ; Return true if count of even_div and odd_div are equals ; Driver Code ; Given Number ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool divisorsSame ( int n ) { int even_div = 0 , odd_div = 0 ; for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { if ( i % 2 == 0 ) { even_div ++ ; } else { odd_div ++ ; } } else { if ( i % 2 == 0 ) { even_div ++ ; } else { odd_div ++ ; } if ( n / i % 2 == 0 ) { even_div ++ ; } else { odd_div ++ ; } } } } return ( even_div == odd_div ) ; } int main ( ) { int N = 6 ; if ( divisorsSame ( N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }
Check if N is a Balanced Prime number or not | C ++ program to check if a given number is Balanced prime ; Utility 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 ; Function that returns true if n is a Balanced prime ; If n is not a prime number or n is the first prime then return false ; Initialize previous_prime to n - 1 and next_prime to n + 1 ; Find next prime number ; Find previous prime number ; Arithmetic mean ; If n is a weak prime ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } bool isBalancedPrime ( int n ) { if ( ! isPrime ( n ) n == 2 ) return false ; int previous_prime = n - 1 ; int next_prime = n + 1 ; while ( ! isPrime ( next_prime ) ) next_prime ++ ; while ( ! isPrime ( previous_prime ) ) previous_prime -- ; int mean = ( previous_prime + next_prime ) / 2 ; if ( n == mean ) return true ; else return false ; } int main ( ) { int n = 53 ; if ( isBalancedPrime ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Count of nodes having odd divisors in the given subtree for Q queries | C ++ implementation to count the number of nodes having odd number of divisors for each query ; Adjacency list for tree . ; Array for values and answer at ith node . ; Function to check whether N has odd divisors or not ; DFS function to pre - compute the answers ; Initialize the count ; Repeat for every child ; Increase the count if current node has odd number of divisors ; Driver Code ; Adjacency List ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define N  100001 NEW_LINE vector < int > adj [ N ] ; int a [ N ] , ans [ N ] ; bool hasOddNumberOfDivisors ( int n ) { if ( ( double ) sqrt ( n ) == ( int ) sqrt ( n ) ) return true ; return false ; } int dfs ( int node , int parent ) { int count = 0 ; for ( auto i = adj [ node ] . begin ( ) ; i != adj [ node ] . end ( ) ; ++ i ) { if ( * i != parent ) { count += dfs ( * i , node ) ; } } if ( hasOddNumberOfDivisors ( a [ node ] ) ) ++ count ; ans [ node ] = count ; return count ; } int main ( ) { int n = 5 , i ; vector < int > q = { 4 , 1 , 5 , 3 } ; adj [ 1 ] . push_back ( 2 ) ; adj [ 2 ] . push_back ( 1 ) ; adj [ 2 ] . push_back ( 3 ) ; adj [ 3 ] . push_back ( 2 ) ; adj [ 3 ] . push_back ( 4 ) ; adj [ 4 ] . push_back ( 3 ) ; adj [ 1 ] . push_back ( 5 ) ; adj [ 5 ] . push_back ( 1 ) ; a [ 1 ] = 4 ; a [ 2 ] = 9 ; a [ 3 ] = 14 ; a [ 4 ] = 100 ; a [ 5 ] = 5 ; dfs ( 1 , -1 ) ; for ( int i = 0 ; i < q . size ( ) ; i ++ ) { cout << ans [ q [ i ] ] << " ▁ " ; } return 0 ; }
Minimum Cost to make all array elements equal using given operations | C ++ implementation to find the minimum cost to make all array elements equal ; Function that returns the cost of making all elements equal to current element ; Compute the lower bound of current element ; Calculate the requirement of add operation ; Calculate the requirement of subtract operation ; Compute minimum of left and right ; Computing the total cost of add and subtract operations ; Function that prints minimum cost of making all elements equal ; Sort the given array ; Calculate minimum from a + r and m ; Compute prefix sum and store in pref array ; Find the minimum cost from the given elements ; Finding the minimum cost from the other cases where minimum cost can occur ; Printing the minimum cost of making all elements equal ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int costCalculation ( int current , int arr [ ] , int n , int pref [ ] , int a , int r , int minimum ) { int index = lower_bound ( arr , arr + n , current ) - arr ; int left = index * current - pref [ index ] ; int right = pref [ n ] - pref [ index ] - ( n - index ) * current ; int res = min ( left , right ) ; left -= res ; right -= res ; int total = res * minimum ; total += left * a ; total += right * r ; return total ; } void solve ( int arr [ ] , int n , int a , int r , int m ) { sort ( arr , arr + n ) ; int minimum = min ( a + r , m ) ; int pref [ n + 1 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) pref [ i + 1 ] = pref [ i ] + arr [ i ] ; int ans = 10000 ; for ( int i = 0 ; i < n ; i ++ ) ans = min ( ans , costCalculation ( arr [ i ] , arr , n , pref , a , r , minimum ) ) ; ans = min ( ans , costCalculation ( pref [ n ] / n , arr , n , pref , a , r , minimum ) ) ; ans = min ( ans , costCalculation ( pref [ n ] / n + 1 , arr , n , pref , a , r , minimum ) ) ; cout << ans << " STRNEWLINE " ; } int main ( ) { int arr [ ] = { 5 , 5 , 3 , 6 , 5 } ; int A = 1 , R = 2 , M = 4 ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; solve ( arr , size , A , R , M ) ; return 0 ; }
Count of integers up to N which represent a Binary number | C ++ Program to count the number of integers upto N which are of the form of binary representations ; Function to return the count ; If the current last digit is 1 ; Add 2 ^ ( ctr - 1 ) possible integers to the answer ; If the current digit exceeds 1 ; Set answer as 2 ^ ctr - 1 as all possible binary integers with ctr number of digits can be obtained ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countBinaries ( int N ) { int ctr = 1 ; int ans = 0 ; while ( N > 0 ) { if ( N % 10 == 1 ) { ans += pow ( 2 , ctr - 1 ) ; } else if ( N % 10 > 1 ) { ans = pow ( 2 , ctr ) - 1 ; } ctr ++ ; N /= 10 ; } return ans ; } int main ( ) { int N = 20 ; cout << countBinaries ( N ) ; return 0 ; }
Count of integers up to N which represent a Binary number | C ++ Program to count the number of integers upto N which are of the form of binary representations ; Function to return the count ; PreCompute and store the powers of 2 ; If the current last digit is 1 ; Add 2 ^ ( ctr - 1 ) possible integers to the answer ; If the current digit exceeds 1 ; Set answer as 2 ^ ctr - 1 as all possible binary integers with ctr number of digits can be obtained ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countBinaries ( int N ) { vector < int > powersOfTwo ( 11 ) ; powersOfTwo [ 0 ] = 1 ; for ( int i = 1 ; i < 11 ; i ++ ) { powersOfTwo [ i ] = powersOfTwo [ i - 1 ] * 2 ; } int ctr = 1 ; int ans = 0 ; while ( N > 0 ) { if ( N % 10 == 1 ) { ans += powersOfTwo [ ctr - 1 ] ; } else if ( N % 10 > 1 ) { ans = powersOfTwo [ ctr ] - 1 ; } ctr ++ ; N /= 10 ; } return ans ; } int main ( ) { int N = 20 ; cout << countBinaries ( N ) ; return 0 ; }
Find the sum of the first Nth Centered Hexadecagonal Number | C ++ program to find the sum of the first N centred hexadecagonal numbers ; Centered_Hexadecagonal number function ; Formula to calculate nth Centered_Hexadecagonal number & return it into main function . ; Function to find the sum of the first N centered hexadecagonal number ; Variable to store the sum ; Loop to iterate through the first N numbers ; Finding the sum ; Driver code ; Display first Nth Centered_Hexadecagonal number
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Centered_Hexadecagonal_num ( int n ) { return ( 8 * n * n - 8 * n + 1 ) ; } int sum_Centered_Hexadecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Hexadecagonal_num ( i ) ; } return summ ; } int main ( ) { int n = 5 ; cout << sum_Centered_Hexadecagonal_num ( n ) ; }
Find the sum of the first N Centered heptagonal number | C ++ program to find the sum of the first N centered heptagonal numbers ; Function to find the N - th centered heptagonal number ; Formula to calculate nth centered heptagonal number ; Function to find the sum of the first N centered heptagonal numbers ; Variable to store the sum ; Iterating through the range 1 to N ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int center_heptagonal_num ( int n ) { return ( 7 * n * n - 7 * n + 2 ) / 2 ; } int sum_center_heptagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += center_heptagonal_num ( i ) ; } return summ ; } int main ( ) { int n = 5 ; cout << ( sum_center_heptagonal_num ( n ) ) ; return 0 ; }
Find the sum of the first N Centered Dodecagonal Number | C ++ program to find the sum of the first N Centred Dodecagonal number ; Function to find the N - th Centered Dodecagonal number ; Formula to calculate nth Centered_Dodecagonal number ; Function to find the sum of the first N Centered_Dodecagonal number ; Variable to store the sum ; Iterating from 1 to N ; Finding the sum ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Centered_Dodecagonal_num ( int n ) { return 6 * n * ( n - 1 ) + 1 ; } int sum_Centered_Dodecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Dodecagonal_num ( i ) ; } return summ ; } int main ( ) { int n = 5 ; cout << sum_Centered_Dodecagonal_num ( n ) ; }
Find the sum of the first N Centered Octagonal Number | C ++ program to find the sum of the first N centered octagonal number ; Function to find the N - th centered octagonal number ; Formula to calculate nth centered octagonal number ; Function to find the sum of the first N centered octagonal numbers ; Variable to store the sum ; Iterating through the range 1 to N ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int center_Octagonal_num ( int n ) { return ( 4 * n * n - 4 * n + 1 ) ; } int sum_center_Octagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += center_Octagonal_num ( i ) ; } return summ ; } int main ( ) { int n = 5 ; cout << ( sum_center_Octagonal_num ( n ) ) ; return 0 ; }
Find the sum of the first N Centered Decagonal Numbers | C ++ program to find the sum of the first N centred decagonal number ; Function to find the N - th centred decagonal number ; Formula to calculate nth centered_decagonal number & return it into main function . ; Function to find the sum of the first N centered decagonal numbers ; Variable to store the sum ; Iterating through the range ; Driver code ; Display first Nth centered_decagonal number
#include <bits/stdc++.h> NEW_LINE using namespace std ; int Centered_decagonal_num ( int n ) { return ( 5 * n * n - 5 * n + 1 ) ; } int sum_Centered_decagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_decagonal_num ( i ) ; } return summ ; } int main ( ) { int n = 5 ; cout << ( sum_Centered_decagonal_num ( n ) ) ; return 0 ; }