dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateSum ( int n ) { if ( n <= 0 ) return 0 ; int fibo [ n + 1 ] ; fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ; int sum = fibo [ 0 ] + fibo [ 1 ] ; for ( int i = 2 ; i <= n ; i ++ ) { fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ; sum += fibo [ i ] ; } return sum ; } int main ( ) { int n = 4 ; cout << " Sum ▁ of ▁ Fibonacci ▁ numbers ▁ is ▁ : ▁ " << calculateSum ( n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 1000 ; int f [ MAX ] = { 0 } ; int fib ( int n ) { if ( n == 0 ) return 0 ; if ( n == 1 n == 2 ) return ( f [ n ] = 1 ) ; if ( f [ n ] ) return f [ n ] ; int k = ( n & 1 ) ? ( n + 1 ) / 2 : n / 2 ; f [ n ] = ( n & 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; return f [ n ] ; } int calculateSum ( int n ) { return fib ( n + 2 ) - 1 ; } int main ( ) { int n = 4 ; cout << " Sum ▁ of ▁ Fibonacci ▁ numbers ▁ is ▁ : ▁ " << calculateSum ( n ) << endl ; return 0 ; }

Index/key variables: MAX, n
Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; void findCombinationsUtil ( int arr [ ] , int index , int num , int reducedNum ) { if ( reducedNum < 0 ) return ; if ( reducedNum == 0 ) { for ( int i = 0 ; i < index ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; return ; } int prev = ( index == 0 ) ? 1 : arr [ index - 1 ] ; for ( int k = prev ; k <= num ; k ++ ) { arr [ index ] = k ; findCombinationsUtil ( arr , index + 1 , num , reducedNum - k ) ; } } void findCombinations ( int n ) { int arr [ n ] ; findCombinationsUtil ( arr , 0 , n , n ) ; } int main ( ) { int n = 5 ; findCombinations ( n ) ; return 0 ; }

Index/key variables: i, index, n
Accumulator variables: i, k
Iterator variables: i, k
C++ program:
#include <iostream>
#include <math.h>
using namespace std ; #define COMPUTER  1
#define HUMAN  2
struct move { int pile_index ; int stones_removed ; } ; void showPiles ( int piles [ ] , int n ) { int i ; cout << " Current ▁ Game ▁ Status ▁ - > ▁ " ; for ( i = 0 ; i < n ; i ++ ) cout << " ▁ " << piles [ i ] ; cout << " STRNEWLINE " ; return ; } bool gameOver ( int piles [ ] , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) if ( piles [ i ] != 0 ) return ( false ) ; return ( true ) ; } void declareWinner ( int whoseTurn ) { if ( whoseTurn == COMPUTER ) cout << " HUMAN won " else cout << " COMPUTER won " return ; } int calculateNimSum ( int piles [ ] , int n ) { int i , nimsum = piles [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) nimsum = nimsum ^ piles [ i ] ; return ( nimsum ) ; } void makeMove ( int piles [ ] , int n , struct move * moves ) { int i , nim_sum = calculateNimSum ( piles , n ) ; if ( nim_sum != 0 ) { for ( i = 0 ; i < n ; i ++ ) { if ( ( piles [ i ] ^ nim_sum ) < piles [ i ] ) { ( * moves ) . pile_index = i ; ( * moves ) . stones_removed = piles [ i ] - ( piles [ i ] ^ nim_sum ) ; piles [ i ] = ( piles [ i ] ^ nim_sum ) ; break ; } } } else { int non_zero_indices [ n ] , count ; for ( i = 0 , count = 0 ; i < n ; i ++ ) if ( piles [ i ] > 0 ) non_zero_indices [ count ++ ] = i ; ( * moves ) . pile_index = ( rand ( ) % ( count ) ) ; ( * moves ) . stones_removed = 1 + ( rand ( ) % ( piles [ ( * moves ) . pile_index ] ) ) ; piles [ ( * moves ) . pile_index ] = piles [ ( * moves ) . pile_index ] - ( * moves ) . stones_removed ; if ( piles [ ( * moves ) . pile_index ] < 0 ) piles [ ( * moves ) . pile_index ] = 0 ; } return ; } void playGame ( int piles [ ] , int n , int whoseTurn ) { cout << " GAME STARTS " struct move moves ; while ( gameOver ( piles , n ) == false ) { showPiles ( piles , n ) ; makeMove ( piles , n , & moves ) ; if ( whoseTurn == COMPUTER ) { cout << " COMPUTER ▁ removes " << moves . stones_removed << " stones ▁ from ▁ pile ▁ at ▁ index ▁ " << moves . pile_index << endl ; whoseTurn = HUMAN ; } else { cout << " HUMAN ▁ removes " << moves . stones_removed << " stones ▁ from ▁ pile ▁ at ▁ index ▁ " << moves . pile_index << endl ; whoseTurn = COMPUTER ; } } showPiles ( piles , n ) ; declareWinner ( whoseTurn ) ; return ; } void knowWinnerBeforePlaying ( int piles [ ] , int n , int whoseTurn ) { cout << " Prediction ▁ before ▁ playing ▁ the ▁ game ▁ - > ▁ " ; if ( calculateNimSum ( piles , n ) != 0 ) { if ( whoseTurn == COMPUTER ) cout << " COMPUTER ▁ will ▁ win STRNEWLINE " ; else cout << " HUMAN ▁ will ▁ win STRNEWLINE " ; } else { if ( whoseTurn == COMPUTER ) cout << " HUMAN ▁ will ▁ win STRNEWLINE " ; else cout << " COMPUTER ▁ will ▁ win STRNEWLINE " ; } return ; } int main ( ) { int piles [ ] = { 3 , 4 , 5 } ; int n = sizeof ( piles ) / sizeof ( piles [ 0 ] ) ; knowWinnerBeforePlaying ( piles , n , COMPUTER ) ; playGame ( piles , n , COMPUTER ) ; knowWinnerBeforePlaying ( piles , n , COMPUTER ) ; return ( 0 ) ; }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
Class/struct names: move
C++ program:
#include <bits/stdc++.h>
using namespace std ; int pow ( int base , int exponent , int modulus ) { int result = 1 ; base = base % modulus ; while ( exponent > 0 ) { if ( exponent % 2 == 1 ) result = ( result * base ) % modulus ; exponent = exponent >> 1 ; base = ( base * base ) % modulus ; } return result ; } int gcd ( int a , int b ) { if ( b == 0 ) return a ; else return gcd ( b , a % b ) ; } int order ( int p , int b ) { if ( gcd ( p , b ) != 1 ) { printf ( " p ▁ and ▁ b ▁ are ▁ not ▁ co - prime . STRNEWLINE " ) ; return -1 ; } int k = 3 ; while ( 1 ) { if ( pow ( b , k , p ) == 1 ) return k ; k ++ ; } } int convertx2e ( int x , int & e ) { e = 0 ; while ( x % 2 == 0 ) { x /= 2 ; e ++ ; } return x ; } int STonelli ( int n , int p ) { if ( gcd ( n , p ) != 1 ) { printf ( " a ▁ and ▁ p ▁ are ▁ not ▁ coprime STRNEWLINE " ) ; return -1 ; } if ( pow ( n , ( p - 1 ) / 2 , p ) == ( p - 1 ) ) { printf ( " no ▁ sqrt ▁ possible STRNEWLINE " ) ; return -1 ; } int s , e ; s = convertx2e ( p - 1 , e ) ; int q ; for ( q = 2 ; ; q ++ ) { if ( pow ( q , ( p - 1 ) / 2 , p ) == ( p - 1 ) ) break ; } int x = pow ( n , ( s + 1 ) / 2 , p ) ; int b = pow ( n , s , p ) ; int g = pow ( q , s , p ) ; int r = e ; while ( 1 ) { int m ; for ( m = 0 ; m < r ; m ++ ) { if ( order ( p , b ) == -1 ) return -1 ; if ( order ( p , b ) == pow ( 2 , m ) ) break ; } if ( m == 0 ) return x ; x = ( x * pow ( g , pow ( 2 , r - m - 1 ) , p ) ) % p ; g = pow ( g , pow ( 2 , r - m ) , p ) ; b = ( b * g ) % p ; if ( b == 1 ) return x ; r = m ; } } int main ( ) { int n = 2 ; int p = 113 ; int x = STonelli ( n , p ) ; if ( x == -1 ) printf ( " Modular ▁ square ▁ root ▁ is ▁ not ▁ exist STRNEWLINE " ) ; else printf ( " Modular ▁ square ▁ root ▁ of ▁ % d ▁ and ▁ % d ▁ is ▁ % d STRNEWLINE " , n , p , x ) ; }

Accumulator variables: e, k, m, q, stdc, x
Iterator variables: m, q
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findRoots ( int a , int b , int c ) { if ( a == 0 ) { cout << " Invalid " ; return ; } int d = b * b - 4 * a * c ; double sqrt_val = sqrt ( abs ( d ) ) ; if ( d > 0 ) { cout << " Roots ▁ are ▁ real ▁ and ▁ different ▁ STRNEWLINE " ; cout << ( double ) ( - b + sqrt_val ) / ( 2 * a ) << " STRNEWLINE " << ( double ) ( - b - sqrt_val ) / ( 2 * a ) ; } else if ( d == 0 ) { cout << " Roots ▁ are ▁ real ▁ and ▁ same ▁ STRNEWLINE " ; cout << - ( double ) b / ( 2 * a ) ; } { cout << " Roots ▁ are ▁ complex ▁ STRNEWLINE " ; cout << - ( double ) b / ( 2 * a ) << " ▁ + ▁ i " << sqrt_val << " STRNEWLINE " << - ( double ) b / ( 2 * a ) << " ▁ - ▁ i " << sqrt_val ; } } int main ( ) { int a = 1 , b = -7 , c = 12 ; findRoots ( a , b , c ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPerfectSquare ( int n ) { for ( int sum = 0 , i = 1 ; sum < n ; i += 2 ) { sum += i ; if ( sum == n ) return true ; } return false ; } int main ( ) { isPerfectSquare ( 35 ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; isPerfectSquare ( 49 ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; return 0 ; }

Accumulator variables: i, stdc, sum
Iterator variables: sum
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCount ( int d ) { return 9 * ( pow ( 10 , d - 1 ) - pow ( 9 , d - 1 ) ) ; } int main ( ) { int d = 1 ; cout << findCount ( d ) << endl ; d = 2 ; cout << findCount ( d ) << endl ; d = 4 ; cout << findCount ( d ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int countDyckPaths ( unsigned int n ) { int res = 1 ; for ( int i = 0 ; i < n ; ++ i ) { res *= ( 2 * n - i ) ; res /= ( i + 1 ) ; } return res / ( n + 1 ) ; } int main ( ) { int n = 4 ; cout << " Number ▁ of ▁ Dyck ▁ Paths ▁ is ▁ " << countDyckPaths ( n ) ; return 0 ; }

Accumulator variables: res
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool isTriangular ( int num ) { if ( num < 0 ) return false ; int sum = 0 ; for ( int n = 1 ; sum <= num ; n ++ ) { sum = sum + n ; if ( sum == num ) return true ; } return false ; } int main ( ) { int n = 55 ; if ( isTriangular ( n ) ) cout << " The ▁ number ▁ is ▁ a ▁ triangular ▁ number " ; else cout << " The ▁ number ▁ is ▁ NOT ▁ a ▁ triangular ▁ number " ; return 0 ; }

Accumulator variables: n
Iterator variables: n
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isTriangular ( int num ) { if ( num < 0 ) return false ; int c = ( -2 * num ) ; int b = 1 , a = 1 ; int d = ( b * b ) - ( 4 * a * c ) ; if ( d < 0 ) return false ; float root1 = ( - b + sqrt ( d ) ) / ( 2 * a ) ; float root2 = ( - b - sqrt ( d ) ) / ( 2 * a ) ; if ( root1 > 0 && floor ( root1 ) == root1 ) return true ; if ( root2 > 0 && floor ( root2 ) == root2 ) return true ; return false ; } int main ( ) { int num = 55 ; if ( isTriangular ( num ) ) cout << " The ▁ number ▁ is ▁ a ▁ triangular ▁ number " ; else cout << " The ▁ number ▁ is ▁ NOT ▁ a ▁ triangular ▁ number " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int gcd ( int a , int b ) { int c ; while ( a != 0 ) { c = a ; a = b % a ; b = c ; } return b ; } void forbenius ( int X , int Y ) { if ( gcd ( X , Y ) != 1 ) { cout << " NA STRNEWLINE " ; return ; } int A = ( X * Y ) - ( X + Y ) ; int N = ( X - 1 ) * ( Y - 1 ) / 2 ; cout << " Largest ▁ Amount ▁ = ▁ " << A << endl ; cout << " Total ▁ Count ▁ = ▁ " << N << endl ; } int main ( ) { int X = 2 , Y = 5 ; forbenius ( X , Y ) ; X = 5 , Y = 10 ; cout << endl ; forbenius ( X , Y ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; char xor_c ( char a , char b ) { return ( a == b ) ? '0' : '1' ; } char flip ( char c ) { return ( c == '0' ) ? '1' : '0' ; } string binarytoGray ( string binary ) { string gray = " " ; gray += binary [ 0 ] ; for ( int i = 1 ; i < binary . length ( ) ; i ++ ) { gray += xor_c ( binary [ i - 1 ] , binary [ i ] ) ; } return gray ; } string graytoBinary ( string gray ) { string binary = " " ; binary += gray [ 0 ] ; for ( int i = 1 ; i < gray . length ( ) ; i ++ ) { if ( gray [ i ] == '0' ) binary += binary [ i - 1 ] ; else binary += flip ( binary [ i - 1 ] ) ; } return binary ; } int main ( ) { string binary = "01001" ; cout << " Gray ▁ code ▁ of ▁ " << binary << " ▁ is ▁ " << binarytoGray ( binary ) << endl ; string gray = "01101" ; cout << " Binary ▁ code ▁ of ▁ " << gray << " ▁ is ▁ " << graytoBinary ( gray ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: binary, gray, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int seriesSum ( int calculated , int current , int N ) { int i , cur = 1 ; if ( current == N + 1 ) return 0 ; for ( i = calculated ; i < calculated + current ; i ++ ) cur *= i ; return cur + seriesSum ( i , current + 1 , N ) ; } int main ( ) { int N = 5 ; cout << seriesSum ( 1 , 1 , N ) << endl ; return 0 ; }

Accumulator variables: cur, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getSum ( int BITree [ ] , int index ) { while ( index > 0 ) { sum += BITree [ index ] ; index -= index & ( - index ) ; } return sum ; } void updateBIT ( int BITree [ ] , int n , int index , int val ) { while ( index <= n ) { BITree [ index ] += val ; index += index & ( - index ) ; } } void convert ( int arr [ ] , int n ) { int temp [ n ] ; for ( int i = 0 ; i < n ; i ++ ) temp [ i ] = arr [ i ] ; sort ( temp , temp + n ) ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = lower_bound ( temp , temp + n , arr [ i ] ) - temp + 1 ; } } int getInvCount ( int arr [ ] , int n ) { convert ( arr , n ) ; int BIT [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) BIT [ i ] = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { invcount += getSum ( BIT , arr [ i ] - 1 ) ; updateBIT ( BIT , n , arr [ i ] , 1 ) ; } return invcount ; } int main ( ) { int arr [ ] = { 8 , 4 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << " Number ▁ of ▁ inversions ▁ are ▁ : ▁ " << getInvCount ( arr , n ) ; return 0 ; }

Index/key variables: i, index, n
Accumulator variables: i, index, invcount, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int modFact ( int n , int p ) { if ( n >= p ) return 0 ; int result = 1 ; for ( int i = 1 ; i <= n ; i ++ ) result = ( result * i ) % p ; return result ; } int main ( ) { int n = 25 , p = 29 ; cout << modFact ( n , p ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int inv ( int a , int m ) { int m0 = m , t , q ; int x0 = 0 , x1 = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { q = a / m ; t = m ; m = a % m , a = t ; t = x0 ; x0 = x1 - q * x0 ; x1 = t ; } if ( x1 < 0 ) x1 += m0 ; return x1 ; } int findMinX ( int num [ ] , int rem [ ] , int k ) { int prod = 1 ; for ( int i = 0 ; i < k ; i ++ ) prod *= num [ i ] ; int result = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int pp = prod / num [ i ] ; result += rem [ i ] * inv ( pp , num [ i ] ) * pp ; } return result % prod ; } int main ( void ) { int num [ ] = { 3 , 4 , 5 } ; int rem [ ] = { 2 , 3 , 1 } ; int k = sizeof ( num ) / sizeof ( num [ 0 ] ) ; cout << " x ▁ is ▁ " << findMinX ( num , rem , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, prod, result, stdc, x1
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinX ( int num [ ] , int rem [ ] , int k ) { while ( true ) { int j ; for ( j = 0 ; j < k ; j ++ ) if ( x % num [ j ] != rem [ j ] ) break ; if ( j == k ) return x ; x ++ ; } return x ; } int main ( void ) { int num [ ] = { 3 , 4 , 5 } ; int rem [ ] = { 2 , 3 , 1 } ; int k = sizeof ( num ) / sizeof ( num [ 0 ] ) ; cout << " x ▁ is ▁ " << findMinX ( num , rem , k ) ; return 0 ; }

Index/key variables: j
Accumulator variables: j, stdc, x
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nCrModpDP ( int n , int r , int p ) { int C [ r + 1 ] ; memset ( C , 0 , sizeof ( C ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = min ( i , r ) ; j > 0 ; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ; } return C [ r ] ; } int nCrModpLucas ( int n , int r , int p ) { if ( r == 0 ) return 1 ; int ni = n % p , ri = r % p ; } int main ( ) { int n = 1000 , r = 900 , p = 13 ; cout << " Value ▁ of ▁ nCr ▁ % ▁ p ▁ is ▁ " << nCrModpLucas ( n , r , p ) ; return 0 ; }

Index/key variables: j, r
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  30
int fib [ N ] ; int largestFiboLessOrEqual ( int n ) { fib [ 0 ] = 1 ; fib [ 1 ] = 2 ; int i ; for ( i = 2 ; fib [ i - 1 ] <= n ; i ++ ) fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; return ( i - 2 ) ; } char * fibonacciEncoding ( int n ) { int index = largestFiboLessOrEqual ( n ) ; char * codeword = ( char * ) malloc ( sizeof ( char ) * ( index + 3 ) ) ; int i = index ; while ( n ) { codeword [ i ] = '1' ; n = n - fib [ i ] ; i = i - 1 ; while ( i >= 0 && fib [ i ] > n ) { codeword [ i ] = '0' ; i = i - 1 ; } } codeword [ index + 1 ] = '1' ; codeword [ index + 2 ] = ' \0' ; return codeword ; } int main ( ) { int n = 143 ; cout << " Fibonacci ▁ code ▁ word ▁ for ▁ " << n << " ▁ is ▁ " << fibonacciEncoding ( n ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isValid ( int n , int d ) { int digit = n % 10 ; int sum = digit ; if ( digit == d ) return false ; n /= 10 ; while ( n ) { digit = n % 10 ; if ( digit == d digit <= sum ) return false ; else { sum += digit ; n /= 10 ; } } return 1 ; } void printGoodNumbers ( int L , int R , int d ) { for ( int i = L ; i <= R ; i ++ ) { if ( isValid ( i , d ) ) cout << i << " ▁ " ; } } int main ( ) { int L = 410 , R = 520 , d = 3 ; printGoodNumbers ( L , R , d ) ; return 0 ; }

Accumulator variables: i, n, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nearestSmallerEqFib ( int n ) { if ( n == 0 n == 1 ) return n ; int f1 = 0 , f2 = 1 , f3 = 1 ; while ( f3 <= n ) { f1 = f2 ; f2 = f3 ; f3 = f1 + f2 ; } return f2 ; } void printFibRepresntation ( int n ) { while ( n > 0 ) { int f = nearestSmallerEqFib ( n ) ; cout << f << " ▁ " ; n = n - f ; } } int main ( ) { int n = 30 ; cout << " Non - neighbouring ▁ Fibonacci ▁ Representation ▁ of ▁ " << n << " ▁ is ▁ STRNEWLINE " ; printFibRepresntation ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 5001 ] [ 5001 ] [ 5 ] ; int countWaysUtil ( int n , int parts , int nextPart ) { if ( parts == 0 && n == 0 ) return 1 ; if ( n <= 0 parts <= 0 ) return 0 ; if ( dp [ n ] [ nextPart ] [ parts ] != -1 ) return dp [ n ] [ nextPart ] [ parts ] ; for ( int i = nextPart ; i <= n ; i ++ ) ans += countWaysUtil ( n - i , parts - 1 , i ) ; return ( dp [ n ] [ nextPart ] [ parts ] = ans ) ; } int countWays ( int n ) { memset ( dp , -1 , sizeof ( dp ) ) ; return countWaysUtil ( n , 4 , 1 ) ; } int main ( ) { int n = 8 ; cout << countWays ( n ) << endl ; return 0 ; }

Index/key variables: n, nextPart, parts
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printTwins ( int low , int high ) { bool prime [ high + 1 ] , twin = false ; memset ( prime , true , sizeof ( prime ) ) ; prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p <= floor ( sqrt ( high ) ) + 1 ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= high ; i += p ) prime [ i ] = false ; } } for ( int i = low ; i <= high ; i ++ ) { if ( prime [ i ] && prime [ i + 2 ] ) { cout << " Smallest ▁ twins ▁ in ▁ given ▁ range : ▁ ( " << i << " , ▁ " << i + 2 << " ) " ; twin = true ; break ; } } if ( twin == false ) cout << " No ▁ such ▁ pair ▁ exists " << endl ; } int main ( ) { printTwins ( 10 , 100 ) ; return 0 ; }

Index/key variables: i, p
Accumulator variables: i, p, stdc
Iterator variables: i, p
Boolean variables: twin
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isFancy ( string & num ) { map < char , char > fp ; fp [ '0' ] = '0' ; fp [ '1' ] = '1' ; fp [ '6' ] = '9' ; fp [ '8' ] = '8' ; fp [ '9' ] = '6' ; int n = num . length ( ) ; int l = 0 , r = n - 1 ; while ( l <= r ) { if ( fp . find ( num [ l ] ) == fp . end ( ) fp [ num [ l ] ] != num [ r ] ) return false ; l ++ ; r -- ; } return true ; } int main ( ) { string str = "9088806" ; isFancy ( str ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Index/key variables: l, r
Accumulator variables: l, r, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nextSparse ( int x ) { vector < bool > bin ; while ( x != 0 ) { bin . push_back ( x & 1 ) ; x >>= 1 ; } bin . push_back ( 0 ) ; int last_final = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( bin [ i ] == 1 && bin [ i - 1 ] == 1 && bin [ i + 1 ] != 1 ) { bin [ i + 1 ] = 1 ; for ( int j = i ; j >= last_final ; j -- ) bin [ j ] = 0 ; last_final = i + 1 ; } } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += bin [ i ] * ( 1 << i ) ; return ans ; } int main ( ) { int x = 38 ; cout << " Next ▁ Sparse ▁ Number ▁ is ▁ " << nextSparse ( x ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void ccountSubsets ( int arr [ ] , int n , int gcd [ ] , int m ) { unordered_map < int , int > freq ; unordered_map < int , int > subsets ; int arrMax = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arrMax = max ( arrMax , arr [ i ] ) ; freq [ arr [ i ] ] ++ ; } for ( int i = arrMax ; i >= 1 ; i -- ) { int sub = 0 ; int add = freq [ i ] ; for ( int j = 2 ; j * i <= arrMax ; j ++ ) { add += freq [ j * i ] ; sub += subsets [ j * i ] ; } subsets [ i ] = ( 1 << add ) - 1 - sub ; } for ( int i = 0 ; i < m ; i ++ ) cout << " Number ▁ of ▁ subsets ▁ with ▁ gcd ▁ " << gcd [ i ] << " ▁ is ▁ " << subsets [ gcd [ i ] ] << endl ; } int main ( ) { int gcd [ ] = { 2 , 3 } ; int arr [ ] = { 9 , 6 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int m = sizeof ( gcd ) / sizeof ( gcd [ 0 ] ) ; ccountSubsets ( arr , n , gcd , m ) ; return 0 ; }

Index/key variables: i
Accumulator variables: add, i, j, stdc, sub
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumBitDifferences ( int arr [ ] , int n ) { for ( int i = 0 ; i < 32 ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) if ( ( arr [ j ] & ( 1 << i ) ) ) count ++ ; ans += ( count * ( n - count ) * 2 ) ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 } ; int n = sizeof arr / sizeof arr [ 0 ] ; cout << sumBitDifferences ( arr , n ) << endl ; return 0 ; }

Index/key variables: j
Accumulator variables: ans, count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; } void generateUtil ( int x , int arr [ ] , int curr_sum , int curr_idx ) { if ( curr_sum == x ) { printArr ( arr , curr_idx ) ; return ; } int num = 1 ; while ( num <= x - curr_sum && ( curr_idx == 0 num <= arr [ curr_idx - 1 ] ) ) { arr [ curr_idx ] = num ; generateUtil ( x , arr , curr_sum + num , curr_idx + 1 ) ; num ++ ; } } void generate ( int x ) { int arr [ x ] ; generateUtil ( x , arr , 0 , 0 ) ; } int main ( ) { int x = 5 ; generate ( x ) ; return 0 ; }

Index/key variables: curr_idx, i, x
Accumulator variables: i, num, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool isPerfect ( long long int n ) { long long int sum = 1 ; for ( long long 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 true ; return false ; } int main ( ) { cout << " Below ▁ are ▁ all ▁ perfect ▁ numbers ▁ till ▁ 10000 STRNEWLINE " ; for ( int n = 2 ; n < 10000 ; n ++ ) if ( isPerfect ( n ) ) cout << n << " ▁ is ▁ a ▁ perfect ▁ number STRNEWLINE " ; return 0 ; }

Accumulator variables: i, n
Iterator variables: i, n
C++ program:
#include <iostream>
using namespace std ; bool checkUtil ( int num , int dig , int base ) { if ( dig == 1 && num < base ) return true ; if ( dig > 1 && num >= base ) return checkUtil ( num / base , -- dig , base ) ; return false ; } bool check ( int num , int dig ) { for ( int base = 2 ; base <= 32 ; base ++ ) if ( checkUtil ( num , dig , base ) ) return true ; return false ; } int main ( ) { int num = 8 ; int dig = 3 ; ( check ( num , dig ) ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Accumulator variables: base
Iterator variables: base
C++ program:
#include <iostream>
using namespace std ; int mod ( string num , int a ) { int res = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) res = ( res * 10 + ( int ) num [ i ] - '0' ) % a ; return res ; } int main ( ) { string num = "12316767678678" ; cout << mod ( num , 10 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i