dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int mod = 1000000007 ; int countSubsets ( int a [ ] , int n ) { int answer = 0 ; int powerOfTwo [ 100005 ] ; powerOfTwo [ 0 ] = 1 ; for ( int i = 1 ; i < 100005 ; i ++ ) powerOfTwo [ i ] = ( powerOfTwo [ i - 1 ] * 2 ) % mod ; unordered_map < int , int > frequency ; for ( int i = 0 ; i < n ; i ++ ) frequency [ a [ i ] ] ++ ; for ( auto el : frequency ) { if ( el . first != 0 ) answer = ( answer % mod + powerOfTwo [ el . second - 1 ] ) % mod ; else answer = ( answer % mod + powerOfTwo [ el . second ] - 1 + mod ) % mod ; } return answer ; } int main ( ) { int N = 6 ; int A [ N ] = { 1 , 3 , 2 , 1 , 2 , 1 } ; cout << countSubsets ( A , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: el, i
C++ program:
#include <bits/stdc++.h>
#define ll  int
using namespace std ; long long pref [ 100010 ] ; int isPerfect ( int n ) { int sum = 1 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i != n ) sum = sum + i + n / i ; else sum = sum + i ; } } if ( sum == n && n != 1 ) return n ; return 0 ; } void precomputation ( ) { for ( int i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfect ( i ) ; } } int main ( ) { int L = 6 , R = 28 ; precomputation ( ) ; cout << pref [ R ] - pref [ L - 1 ] ; return 0 ; }

Index/key variables: R, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std ; void convertToDecimal ( int N ) { cout << " Decimal ▁ number ▁ of ▁ " << N << " ▁ is : ▁ " ; if ( N != 0 ) { int decimalNumber = 0 , i = 0 , remainder ; while ( N != 0 ) { remainder = N % 10 ; N /= 10 ; decimalNumber += remainder * pow ( 3 , i ) ; ++ i ; } cout << decimalNumber << endl ; } else cout << "0" << endl ; } int main ( ) { int Ternary = 10202202 ; convertToDecimal ( Ternary ) ; return 0 ; }

Accumulator variables: N, decimalNumber
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPerfectSquare ( int N ) { double sr = sqrt ( N ) ; return ( sr - floor ( sr ) ) == 0 ; } void BetrothedNumbers ( int n , int m ) { int Sum1 = 1 ; int Sum2 = 1 ; for ( int i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { Sum1 += i + ( isPerfectSquare ( n ) ? 0 : n / i ) ; } } for ( int i = 2 ; i <= sqrt ( m ) ; i ++ ) { if ( m % i == 0 ) { Sum2 += i + ( isPerfectSquare ( m ) ? 0 : m / i ) ; } } if ( ( n + 1 == Sum2 ) && ( m + 1 == Sum1 ) ) { cout << " YES " << endl ; } else { cout << " NO " << endl ; } } int main ( ) { int N = 9504 ; int M = 20734 ; BetrothedNumbers ( N , M ) ; return 0 ; }

Accumulator variables: Sum1, Sum2, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int EulerTotientFunction ( int limit ) { int copy = limit ; vector < int > primes ; for ( int i = 2 ; i * i <= limit ; i ++ ) { if ( limit % i == 0 ) { while ( limit % i == 0 ) { limit /= i ; } primes . push_back ( i ) ; } } if ( limit >= 2 ) { primes . push_back ( limit ) ; } int ans = copy ; for ( auto it : primes ) { ans = ( ans / it ) * ( it - 1 ) ; } return ans ; } void CountGCD ( int m , int k ) { if ( m % k != 0 ) { cout << 0 << endl ; return ; } if ( m == k ) { cout << 2 << endl ; return ; } int limit = m / k ; int ans = EulerTotientFunction ( limit ) ; cout << ans << endl ; } int main ( ) { int M = 9 ; int K = 1 ; CountGCD ( M , K ) ; return 0 ; }

Accumulator variables: i, limit, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long product ( vector < vector < int > > & mat , int n ) { long long d1 = 0 , d2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { d1 += mat [ i ] [ i ] ; d2 += mat [ i ] [ n - i - 1 ] ; } return 1LL * d1 * d2 ; } int main ( ) { vector < vector < int > > mat = { { 5 , 8 , 1 } , { 5 , 10 , 3 } , { -6 , 17 , -9 } } ; int n = mat . size ( ) ; cout << product ( mat , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: d1, d2, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; float getPercentile ( int rank , int students ) { float result = float ( students - rank ) / students * 100 ; return result ; } int main ( ) { int your_rank = 805 ; int total_students = 97481 ; cout << getPercentile ( your_rank , total_students ) ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1000000
int fib ( int n ) { double phi = ( 1 + sqrt ( 5 ) ) / 2 ; return round ( pow ( phi , n ) / sqrt ( 5 ) ) ; } int calculateSum ( int l , int r ) { int sum = fib ( r + 2 ) - fib ( l + 1 ) ; return sum ; } int sumFibonacci ( int k ) { int l = ( k * ( k - 1 ) ) / 2 ; int r = l + k ; int sum = calculateSum ( l , r - 1 ) ; return sum ; } int main ( ) { int k = 3 ; cout << sumFibonacci ( k ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; void sumOfPrevK ( int N , int K ) { int arr [ N ] ; arr [ 0 ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) { int j = i - 1 , count = 0 , sum = 0 ; while ( j >= 0 && count < K ) { sum += arr [ j ] ; j -- ; count ++ ; } arr [ i ] = sum ; } for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } int main ( ) { int N = 10 , K = 4 ; sumOfPrevK ( N , K ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: count, i, j, sum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void sumOfPrevK ( int N , int K ) { int arr [ N ] , prevsum = 0 ; arr [ 0 ] = 1 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( i < K ) { arr [ i + 1 ] = arr [ i ] + prevsum ; prevsum = arr [ i + 1 ] ; } else { arr [ i + 1 ] = arr [ i ] + prevsum - arr [ i + 1 - K ] ; prevsum = arr [ i + 1 ] ; } } for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } int main ( ) { int N = 8 , K = 3 ; sumOfPrevK ( N , K ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int gcd ( int a , int b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } void findMaxGCD ( int arr [ ] , int n ) { int maxGCD = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int val = gcd ( arr [ i ] , arr [ i + 1 ] ) ; if ( val > maxGCD ) { maxGCD = val ; } } cout << maxGCD << endl ; } int main ( ) { int arr [ ] = { 3 , 18 , 9 , 9 , 5 , 15 , 8 , 7 , 6 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findMaxGCD ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( int * arr , int n , int left , int right ) { int k = right - left ; int d = arr [ 1 ] - arr [ 0 ] ; int ans = arr [ left - 1 ] * ( k + 1 ) ; ans = ans + ( d * ( k * ( k + 1 ) ) ) / 2 ; return ans ; } int main ( ) { int arr [ ] = { 2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 } ; int queries = 3 ; int q [ queries ] [ 2 ] = { { 2 , 4 } , { 2 , 6 } , { 5 , 6 } } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; for ( int i = 0 ; i < queries ; i ++ ) cout << findSum ( arr , n , q [ i ] [ 0 ] , q [ i ] [ 1 ] ) << endl ; }

Index/key variables: i, queries
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int subarrayPossible ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum <= 0 ) return 1 ; } sum = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { sum += arr [ i ] ; if ( sum <= 0 ) return 1 ; } return 0 ; } int main ( ) { int arr [ ] = { 10 , 5 , -12 , 7 , -10 , 20 , 30 , -10 , 50 , 60 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( subarrayPossible ( arr , size ) ) cout << " Yes " << " STRNEWLINE " ; else cout << " No " << " STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; float y ( float x ) { float num = 1 ; float denom = 1.0 + x * x ; return num / denom ; } float WeedleRule ( float a , float b ) { double h = ( b - a ) / 6 ; float sum = 0 ; sum = sum + ( ( ( 3 * h ) / 10 ) * ( y ( a ) + y ( a + 2 * h ) + 5 * y ( a + h ) + 6 * y ( a + 3 * h ) + y ( a + 4 * h ) + 5 * y ( a + 5 * h ) + y ( a + 6 * h ) ) ) ; return sum ; } int main ( ) { float a = 0 , b = 6 ; cout << " f ( x ) ▁ = ▁ " << fixed << WeedleRule ( a , b ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
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 findSmallest ( int N ) { if ( N == 0 ) return 2 ; if ( N == 1 ) return 1 ; int prime = N , counter = 0 ; bool found = false ; while ( ! found ) { if ( isPrime ( prime ) ) found = true ; else { prime ++ ; counter ++ ; } } return counter ; } int main ( ) { int N = 10 ; cout << findSmallest ( N ) ; return 0 ; }

Accumulator variables: counter, prime, stdc
Iterator variables: i
Boolean variables: found
C++ program:
#include <bits/stdc++.h>
#define limit  10000000
using namespace std ; int position [ limit + 1 ] ; void sieve ( ) { position [ 0 ] = -1 , position [ 1 ] = -1 ; int pos = 0 ; for ( int i = 2 ; i <= limit ; i ++ ) { if ( position [ i ] == 0 ) { position [ i ] = ++ pos ; for ( int j = i * 2 ; j <= limit ; j += i ) position [ j ] = -1 ; } } } int main ( ) { sieve ( ) ; int n = 11 ; cout << position [ n ] ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; double maxSubArraySum ( double a [ ] , int size ) { double max_so_far = INT_MIN , max_ending_here = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } double minPossibleSum ( double a [ ] , int n , double x ) { double mxSum = maxSubArraySum ( a , n ) ; double sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } sum = sum - mxSum + mxSum / x ; cout << setprecision ( 2 ) << sum << endl ; } int main ( ) { int N = 3 ; double X = 2 ; double A [ N ] = { 1 , -2 , 3 } ; minPossibleSum ( A , N , X ) ; }

Index/key variables: N, i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkPermutation ( int arr [ ] , int n ) { long long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; long long prefix [ n + 1 ] = { 0 } ; prefix [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) prefix [ i ] = prefix [ i - 1 ] + arr [ i ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { long long lsum = prefix [ i ] ; long long rsum = sum - prefix [ i ] ; long long l_len = i + 1 , r_len = n - i - 1 ; if ( ( ( 2 * lsum ) == ( l_len * ( l_len + 1 ) ) ) && ( ( 2 * rsum ) == ( r_len * ( r_len + 1 ) ) ) ) return true ; } return false ; } void printPermutations ( int arr [ ] , int n , int l1 , int l2 ) { for ( int i = 0 ; i < l1 ; i ++ ) { cout << arr [ i ] << " ▁ " ; } cout << endl ; for ( int i = l1 ; i < n ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } void findPermutations ( int arr [ ] , int n ) { if ( ! checkPermutation ( arr , n ) ) { cout << " Not ▁ Possible " ; return ; } int l1 = 0 , l2 = 0 ; l1 = * max_element ( arr , arr + n ) ; l2 = n - l1 ; set < int > s1 , s2 ; for ( int i = 0 ; i < l1 ; i ++ ) s1 . insert ( arr [ i ] ) ; for ( int i = l1 ; i < n ; i ++ ) s2 . insert ( arr [ i ] ) ; if ( s1 . size ( ) == l1 && s2 . size ( ) == l2 ) printPermutations ( arr , n , l1 , l2 ) ; else { swap ( l1 , l2 ) ; printPermutations ( arr , n , l1 , l2 ) ; } } int main ( ) { int arr [ ] = { 2 , 1 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 , 10 , 2 } ; int n = sizeof ( arr ) / sizeof ( int ) ; findPermutations ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int reverse ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } int countReverse ( int arr [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( reverse ( arr [ i ] ) == arr [ j ] ) { res ++ ; } return res ; } int main ( ) { int a [ ] = { 16 , 61 , 12 , 21 , 25 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << countReverse ( a , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, res, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int reverse ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } int countReverse ( int arr [ ] , int n ) { unordered_map < int , int > freq ; for ( int i = 0 ; i < n ; ++ i ) ++ freq [ arr [ i ] ] ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { -- freq [ arr [ i ] ] ; res += freq [ reverse ( arr [ i ] ) ] ; } return res ; } int main ( ) { int a [ ] = { 16 , 61 , 12 , 21 , 25 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << countReverse ( a , n ) << ' ' ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MOD  1000000007
int rangeSum ( int l , int r ) { int a = 1 , b = 9 , res = 0 ; for ( int i = 1 ; i <= 10 ; i ++ ) { int L = max ( l , a ) ; int R = min ( r , b ) ; if ( L <= R ) { int sum = ( L + R ) * ( R - L + 1 ) / 2 ; res += pow ( i , i ) * ( sum % MOD ) ; res %= MOD ; } a = a * 10 ; b = b * 10 + 9 ; } return res ; } int main ( ) { int l = 98 , r = 102 ; cout << rangeSum ( l , r ) ; return 0 ; }

Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int TrialDivision ( int N ) { int i = 2 ; int k = ceil ( sqrt ( N ) ) ; while ( i <= k ) { if ( N % i == 0 ) return 0 ; i += 1 ; } return 1 ; } int main ( ) { int N = 49 ; int p = TrialDivision ( N ) ; if ( p ) cout << ( " Prime " ) ; else cout << ( " Composite " ) ; return 0 ; }

Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void isPossible ( int A [ ] , int n , int k ) { int countOfTwo = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] % 2 == 0 ) { countOfTwo ++ ; } } if ( k == 0 && countOfTwo == n ) cout << " NO STRNEWLINE " ; else if ( countOfTwo >= k ) { cout << " Yes STRNEWLINE " ; } else cout << " No STRNEWLINE " ; } int main ( ) { int arr [ ] = { 1 , 2 , 4 , 5 } ; int K = 2 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; isPossible ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: countOfTwo, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int pairs ( int n ) { vector < vector < int > > c ( 10 , vector < int > ( 10 , 0 ) ) ; int tmp = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i >= tmp * 10 ) tmp *= 10 ; c [ i / tmp ] [ i % 10 ] ++ ; } long long ans = 0 ; for ( int i = 1 ; i < 10 ; i ++ ) for ( int j = 1 ; j < 10 ; j ++ ) ans += ( long long ) c [ i ] [ j ] * c [ j ] [ i ] ; return ans ; } int main ( ) { int n = 25 ; cout << pairs ( n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc, tmp
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countWays ( int A , int B , int C ) { int minAddA = max ( 0 , ( C + B - A + 2 ) / 2 ) ; int count_ways = max ( C - minAddA + 1 , 0 ) ; return count_ways ; } int main ( ) { int A = 3 , B = 5 , C = 5 ; cout << countWays ( A , B , C ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void createHash ( set < int > & hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . insert ( prev ) ; hash . insert ( curr ) ; while ( curr <= maxElement ) { int temp = curr + prev ; hash . insert ( temp ) ; prev = curr ; curr = temp ; } } int gcdFibonacciFreq ( int arr [ ] , int n ) { set < int > hash ; createHash ( hash , * max_element ( arr , arr + n ) ) ; int i , j ; unordered_map < int , int > m ; for ( i = 0 ; i < n ; i ++ ) m [ arr [ i ] ] ++ ; int gcd = 0 ; for ( auto it = m . begin ( ) ; it != m . end ( ) ; it ++ ) { if ( hash . find ( it -> second ) != hash . end ( ) ) { gcd = __gcd ( gcd , it -> first ) ; } } return gcd ; } int main ( ) { int arr [ ] = { 5 , 3 , 6 , 5 , 6 , 6 , 5 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << gcdFibonacciFreq ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, it, stdc
Iterator variables: i, it
C++ program:
#include " bits / stdc + + . h "
using namespace std ; void printSeries ( int N ) { int ith_term = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { ith_term = i % 2 == 0 ? 2 * i * i + 1 : 2 * i * i - 1 ; cout << ith_term << " , ▁ " ; } } int main ( ) { int N = 7 ; printSeries ( N ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findNthTerm ( int N ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { ans = ans + 6 ; } else { ans = ans + 2 ; } } cout << ans << endl ; } int main ( ) { int N = 3 ; findNthTerm ( N ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define size  10001
using namespace std ; int prime [ size ] ; int freq [ size ] ; void sieve ( int a , int b ) { prime [ 1 ] = 1 ; for ( int i = 2 ; i * i < size ; i ++ ) { if ( prime [ i ] == 0 ) { for ( int j = i * 2 ; j < size ; j += i ) prime [ j ] = 1 ; } } for ( int p = 1 ; p < size ; p ++ ) { for ( int q = 1 ; q < size ; q ++ ) { if ( prime [ p ] == 0 && prime [ q ] == 0 && a * p + b * q < size ) { freq [ a * p + b * q ] ++ ; } } } } int main ( ) { int queries = 2 , a = 1 , b = 2 ; sieve ( a , b ) ; int arr [ queries ] = { 15 , 25 } ; for ( int i = 0 ; i < queries ; i ++ ) { cout << freq [ arr [ i ] ] << " ▁ " ; } return 0 ; }

Index/key variables: i, j, p, q, queries, size
Accumulator variables: i, j, p, q, stdc
Iterator variables: i, j, p, q
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printSeriesSum ( int N ) { double sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( i & 1 ) { sum += ( double ) i / ( i + 1 ) ; } else { sum -= ( double ) i / ( i + 1 ) ; } } cout << sum << endl ; } int main ( ) { int N = 10 ; printSeriesSum ( N ) ; return 0 ; }

Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printSeriesSum ( int N ) { long long sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += pow ( i , i - 1 ) ; } cout << sum << endl ; } int main ( ) { int N = 5 ; printSeriesSum ( N ) ; return 0 ; }

Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void printSumSeries ( int N ) { float sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += 1.0 / ( 2 * i - 1 ) ; } cout << sum << endl ; } int main ( ) { int N = 6 ; printSumSeries ( N ) ; return 0 ; }

Accumulator variables: i, sum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void printSeriesSum ( int N ) { double sum = 0 ; int a = 1 ; int cnt = 0 ; bool flag = true ; sum += a ; while ( cnt < N ) { int nextElement ; if ( flag ) { nextElement = a * 2 ; sum += nextElement ; flag = ! flag ; } else { nextElement = a * 3 / 2 ; sum += nextElement ; flag = ! flag ; } a = nextElement ; cnt ++ ; } cout << sum << endl ; } int main ( ) { int N = 8 ; printSeriesSum ( N ) ; return 0 ; }

Accumulator variables: cnt, sum
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; string sumBaseB ( string a , string b , int base ) { int len_a , len_b ; len_a = a . size ( ) ; len_b = b . size ( ) ; string sum , s ; s = " " ; sum = " " ; int diff ; diff = abs ( len_a - len_b ) ; for ( int i = 1 ; i <= diff ; i ++ ) s += "0" ; if ( len_a < len_b ) a = s + a ; else b = s + b ; int curr , carry = 0 ; for ( int i = max ( len_a , len_b ) - 1 ; i > -1 ; i -- ) { curr = carry + ( a [ i ] - '0' ) + ( b [ i ] - '0' ) ; carry = curr / base ; curr = curr % base ; sum = ( char ) ( curr + '0' ) + sum ; } if ( carry > 0 ) sum = ( char ) ( carry + '0' ) + sum ; return sum ; } int main ( ) { string a , b , sum ; int base ; a = "123" ; b = "234" ; base = 6 ; sum = sumBaseB ( a , b , base ) ; cout << sum << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void MinimumSwapOperations ( string s ) { bool zero_exist = false ; bool multiple_of_2 = false ; int sum = 0 ; int index_of_zero ; bool more_zero = false ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int val = s [ i ] - '0' ; if ( zero_exist == true ) more_zero = true ; if ( val == 0 ) { zero_exist = true ; index_of_zero = i ; } sum += val ; } if ( zero_exist == false sum % 3 != 0 ) { cout << " - 1" << " STRNEWLINE " ; return ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int val = s [ i ] - '0' ; if ( val % 2 == 0 && i != index_of_zero ) multiple_of_2 = true ; } if ( multiple_of_2 == false ) { cout << " - 1" << " STRNEWLINE " ; return ; } int last_val = s [ s . length ( ) - 1 ] - '0' ; int second_last_val = s [ s . length ( ) - 2 ] - '0' ; if ( last_val == 0 && second_last_val % 2 == 0 ) cout << 0 << " STRNEWLINE " ; else if ( ( last_val == 0 && second_last_val % 2 != 0 ) || ( last_val % 2 == 0 && second_last_val == 0 ) ) cout << 1 << " STRNEWLINE " ; else if ( more_zero == true && ( last_val == 0 && second_last_val % 2 != 0 ) ) cout << 1 << " STRNEWLINE " ; else cout << 2 << " STRNEWLINE " ; } int main ( ) { string N = "20" ; MinimumSwapOperations ( N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
Boolean variables: more_zero, multiple_of_2, zero_exist
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 100000 ; int max_prime [ MAX ] ; int min_prime [ MAX ] ; void sieve ( int n ) { for ( int i = 2 ; i <= n ; ++ i ) { if ( min_prime [ i ] > 0 ) { continue ; } min_prime [ i ] = i ; max_prime [ i ] = i ; int j = i + i ; while ( j <= n ) { if ( min_prime [ j ] == 0 ) { min_prime [ j ] = i ; } max_prime [ j ] = i ; j += i ; } } } int findCost ( int A , int B , int C , int X ) { sieve ( MAX ) ; int N , M ; if ( X == 1 ) { return -1 ; } int min_cost = C + X ; int cost_for_prime = A ; N = max_prime [ X ] ; if ( N != X ) { M = X / N ; cost_for_prime += M ; min_cost = min ( min_cost , cost_for_prime ) ; } M = min_prime [ X ] ; N = X / M ; if ( N != min_prime [ N ] ) { int cost_for_comp = B + M ; min_cost = min ( min_cost , cost_for_comp ) ; } return min_cost ; } int main ( ) { int A = 7 , B = 11 , C = 2 , X = 20 ; cout << findCost ( A , B , C , X ) << " ▁ " ; return 0 ; }

Index/key variables: MAX, N, X, i, j
Accumulator variables: cost_for_prime, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countdigits ( int n , int k ) { if ( n == 0 ) return 0 ; int digit = n % 10 ; if ( digit == k ) return 1 + countdigits ( n / 10 , k ) ; return countdigits ( n / 10 , k ) ; } int main ( ) { int n = 1000 ; int k = 0 ; cout << countdigits ( n , k ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; void printModulus ( int X , int Y ) { int n = max ( X , Y ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( X % i == Y % i ) cout << i << " ▁ " ; } } int main ( ) { int X , Y ; X = 10 ; Y = 20 ; printModulus ( X , Y ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void printModulus ( int X , int Y ) { int d = abs ( X - Y ) ; int i = 1 ; while ( i * i <= d ) { if ( d % i == 0 ) { cout << i << " ▁ " ; if ( d / i != i ) cout << d / i << " ▁ " ; } i ++ ; } } int main ( ) { int X = 10 ; int Y = 26 ; printModulus ( X , Y ) ; return 0 ; }

Accumulator variables: i