dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def binomial_coefficient ( n , m ) :
    res = 1
    if m > n - m :
        m = n - m
    for i in range ( 0 , m ) :
        res *= ( n - i )
        res /= ( i + 1 )
    return res
def calculate_ways ( m , n ) :
    if m < n :
        return 0
    ways = binomial_coefficient ( n + m - 1 , n - 1 )
    return int ( ways )
if __name__ == ' _ _ main _ _ ' :
    m = 7 ; n = 5
    result = calculate_ways ( m , n )
    print ( result )

Accumulator variables: res
Iterator variables: i
Python program:
def binaryToDecimal ( n ) :
    num = n
    dec_value = 0
    base = 1
    l = len ( num )
    for i in range ( l - 1 , - 1 , - 1 ) :
        if ( num [ i ] == '1' ) :
            dec_value += base
        base = base * 2
    return dec_value
def numberSequence ( n ) :
    if ( n == 1 ) :
        return 1
    s = " "
    for i in range ( 1 , n ) :
        s += '1'
    s += '0'
    for i in range ( 1 , n + 1 ) :
        s += '1'
    num = binaryToDecimal ( s )
    return num
if __name__ == " _ _ main _ _ " :
    n = 4
    print ( numberSequence ( n ) )

Index/key variables: i
Accumulator variables: dec_value, s
Iterator variables: i
Python program:
def prime ( num ) :
    flag = 0
    for i in range ( 2 , num // 2 + 1 ) :
        if num % i == 0 :
            flag = 1
            break
    if flag == 0 :
        return 1
    else :
        return 0
def print_alternate_prime ( n ) :
    counter = 0
    for num in range ( 2 , n ) :
        if prime ( num ) == 1 :
            if counter % 2 == 0 :
                print ( num , end = " ▁ " )
            counter += 1
if __name__ == " _ _ main _ _ " :
    n = 15
    print ( " Following ▁ are ▁ the ▁ alternate ▁ prime " + " number ▁ smaller ▁ than ▁ or ▁ equal ▁ to " , n )
    print_alternate_prime ( n )

Accumulator variables: counter
Iterator variables: i, num
Python program:
def SieveOfEratosthenes ( n ) :
    prime = [ None ] * ( n + 1 )
    for i in range ( len ( prime ) ) :
        prime [ i ] = True
    p = 2
    while p * p <= n :
        if ( prime [ p ] == True ) :
            for i in range ( p * 2 , n + 1 , p ) :
                prime [ i ] = False
        p += 1
    flag = True
    for p in range ( 2 , n + 1 ) :
        if ( prime [ p ] ) :
            if ( flag ) :
                print ( str ( p ) , end = " ▁ " )
                flag = False
            else :
                flag = True
if __name__ == " _ _ main _ _ " :
    n = 15
    print ( " Following ▁ are ▁ the ▁ alternate " + " ▁ prime ▁ numbers ▁ smaller ▁ " + " than ▁ or ▁ equal ▁ to ▁ " + str ( n ) )
    SieveOfEratosthenes ( n )

Index/key variables: i, p
Iterator variables: i, p
Boolean variables: flag
Python program:
def max_profit ( a , b , n , fee ) :
    i , j , profit = 1 , n - 1 , 0
    l , r , diff_day = 0 , 0 , 1
    b [ 0 ] = 0
    b [ 1 ] = diff_day
    for i in range ( 1 , n ) :
        l = 0
        r = diff_day
        Sum = 0
        for j in range ( n - 1 , i - 1 , - 1 ) :
            profit = ( a [ r ] - a [ l ] ) - fee
            if ( profit > 0 ) :
                Sum = Sum + profit
            l += 1
            r += 1
        if ( b [ 0 ] < Sum ) :
            b [ 0 ] = Sum
            b [ 1 ] = diff_day
    diff_day += 1
    return 0
arr = [ 6 , 1 , 7 , 2 , 8 , 4 ]
n = len ( arr )
b = [ 0 for i in range ( 2 ) ]
tranFee = 2
max_profit ( arr , b , n , tranFee )
print ( b [ 0 ] , " , " , b [ 1 ] )

Index/key variables: l, r
Iterator variables: i, j
Python program:
def binomialCoeff ( x , n , k ) :
    sum = 0 ;
    term = 1 ;
    i = 1 ;
    while ( i <= n and sum < k ) :
        term *= x - i + 1 ;
        term /= i ;
        sum += term ;
        i += 1 ;
    return sum ;
def minTrials ( n , k ) :
    low = 1 ;
    high = k ;
    while ( low < high ) :
        mid = int ( ( low + high ) / 2 ) ;
        if ( binomialCoeff ( mid , n , k ) < k ) :
            low = mid + 1 ;
        else :
            high = mid ;
    return int ( low ) ;
print ( minTrials ( 2 , 10 ) ) ;

Accumulator variables: i, sum, term
Python program:
import math as mt
def isPrime ( num ) :
    if ( num < 2 or num % 2 == 0 ) :
        return num == 2
    for i in range ( 3 , mt . ceil ( mt . sqrt ( num + 1 ) ) ) :
        if ( num % i == 0 ) :
            return False
    return True
def primePalindrome ( N ) :
    if ( 8 <= N and N <= 11 ) :
        return 11
    for x in range ( 1 , 100000 ) :
        s = str ( x )
        d = s [ : : - 1 ]
        y = int ( s + d [ 1 : ] )
        if ( y >= N and isPrime ( y ) ) :
            return y
print ( primePalindrome ( 112 ) )

Iterator variables: i, x
Python program:
def getsum ( a ) :
    r = 0
    sum = 0
    while ( a > 0 ) :
        r = a % 10
        sum = sum + r
        a = a // 10
    return sum
def value ( a , b , c ) :
    x = 0
    q = 0
    w = 0
    v = [ ]
    for i in range ( 1 , 82 ) :
        no = pow ( i , a )
        no = b * no + c
        if ( no > 0 and no < 1000000000 ) :
            x = getsum ( no )
            if ( x == i ) :
                q += 1
                v . append ( no )
                w += 1
    for i in range ( len ( v ) ) :
        print ( v [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    a = 2
    b = 2
    c = - 1
    value ( a , b , c )

Index/key variables: i
Accumulator variables: q, v, w
Iterator variables: i
Python program:
def print_t ( p0 ) :
    i = 0 ;
    while ( True ) :
        flag = 1 ;
        x = pow ( 2 , i ) ;
        p1 = x * p0 - ( x - 1 ) ;
        for k in range ( 2 , p1 ) :
            if ( p1 % k == 0 ) :
                flag = 0 ;
                break ;
        if ( flag == 0 ) :
            break ;
        print ( p1 , end = " ▁ " ) ;
        i += 1 ;
p0 = 19 ;
print_t ( p0 ) ;

Accumulator variables: i
Iterator variables: k
Python program:
def countTriangles ( p ) :
    store = [ ]
    if p % 2 != 0 : return 0
    else :
        count = 0
        for b in range ( 1 , p // 2 ) :
            a = p / 2 * ( ( p - 2 * b ) / ( p - b ) )
            inta = int ( a )
            if ( a == inta ) :
                ab = tuple ( sorted ( ( inta , b ) ) )
                if ab not in store :
                    count += 1
                    store . append ( ab )
        return count
p = 840
print ( " number ▁ of ▁ right ▁ triangles ▁ = ▁ " + str ( countTriangles ( p ) ) )

Accumulator variables: count, store
Iterator variables: b
Python program:
def findOddPair ( A , N ) :
    count = 0 ;
    for i in range ( 0 , N - 1 ) :
        if ( ( A [ i ] % 2 == 1 ) ) :
            count = count + 1
    return count * ( count - 1 ) / 2
a = [ 5 , 1 , 3 , 2 ]
n = len ( a )
print ( int ( findOddPair ( a , n ) ) )

Index/key variables: i
Iterator variables: i
Python program:
def isSurd ( n ) :
    i = 2
    for i in range ( 2 , ( i * i ) + 1 ) :
        j = i
        while ( j < n ) :
            j = j * i
        if ( j == n ) :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    n = 15
    if ( isSurd ( n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Iterator variables: i
Python program:
def power ( x , y , p ) :
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % p
        x = ( x * x ) % p
    return res
def numberOfDigits ( x ) :
    i = 0
    while ( x ) :
        x //= 10
        i += 1
    return i
def LastTwoDigit ( n ) :
    print ( " Last ▁ " + str ( 2 ) + " ▁ digits ▁ of ▁ " + str ( 2 ) , end = " " )
    print ( " ^ " + str ( n ) + " ▁ = ▁ " , end = " " )
    temp = 1
    for i in range ( 1 , 3 ) :
        temp *= 10
    temp = power ( 2 , n , temp )
    for i in range ( 2 - numberOfDigits ( temp ) ) :
        print ( 0 , end = " " )
    if temp :
        print ( temp )
if __name__ == " _ _ main _ _ " :
    n = 72
    LastTwoDigit ( n )

Accumulator variables: temp, x
Iterator variables: i
Python program:
def countOddSum ( ar , n ) :
    result = 0
    for i in range ( n ) :
        val = 0
        for j in range ( i , n ) :
            val = val + ar [ j ]
            if ( val % 2 != 0 ) :
                result += 1
    return ( result )
ar = [ 5 , 4 , 4 , 5 , 1 , 3 ]
print ( " The ▁ Number ▁ of ▁ Subarrays " , " with ▁ odd " , end = " " )
print ( " ▁ sum ▁ is ▁ " + str ( countOddSum ( ar , 6 ) ) )

Index/key variables: j
Accumulator variables: result
Iterator variables: i, j
Python program:
def countOddSum ( ar , n ) :
    temp = [ 1 , 0 ]
    result = 0
    val = 0
    for i in range ( n ) :
        val = ( ( val + ar [ i ] ) % 2 + 2 ) % 2
        temp [ val ] += 1
    result = ( temp [ 0 ] * temp [ 1 ] )
    return ( result )
ar = [ 5 , 4 , 4 , 5 , 1 , 3 ]
print ( " The ▁ Number ▁ of ▁ Subarrays " " ▁ with ▁ odd ▁ sum ▁ is ▁ " + str ( countOddSum ( ar , 6 ) ) )

Index/key variables: i, val
Iterator variables: i
Python program:
def printPFsInPairs ( n ) :
    for i in range ( 1 , int ( pow ( n , 1 / 2 ) ) + 1 ) :
        if n % i == 0 :
            print ( str ( i ) + " * " + str ( int ( n / i ) ) )
n = 24
printPFsInPairs ( n )

Iterator variables: i
Python program:
def rangesum ( n , l , r ) :
    arr = [ 0 ] * n ;
    c = 1 ; i = 0 ;
    while ( c <= n ) :
        arr [ i ] = c ;
        i += 1 ;
        c += 2 ;
    c = 2 ;
    while ( c <= n ) :
        arr [ i ] = c ;
        i += 1 ;
        c += 2 ;
    sum = 0 ;
    for i in range ( l - 1 , r , 1 ) :
        sum += arr [ i ] ;
    return sum ;
if __name__ == ' _ _ main _ _ ' :
    n = 12 ;
    l , r = 1 , 11 ;
    print ( rangesum ( n , l , r ) ) ;

Index/key variables: i
Accumulator variables: c, sum
Iterator variables: i
Python program:
def DivisibleBy41 ( first , second , c , n ) :
    digit = [ 0 ] * n
    digit [ 0 ] = first
    digit [ 1 ] = second
    for i in range ( 2 , n ) :
        digit [ i ] = ( digit [ i - 1 ] * c + digit [ i - 2 ] ) % 10
    ans = digit [ 0 ]
    for i in range ( 1 , n ) :
        ans = ( ans * 10 + digit [ i ] ) % 41
    if ( ans % 41 == 0 ) :
        return True
    else :
        return False
first = 1
second = 2
c = 1
n = 3
if ( DivisibleBy41 ( first , second , c , n ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i
Iterator variables: i
Python program:
def findTetrahedralNumber ( n ) :
    return ( int ( ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ) )
def printSeries ( n ) :
    prev = 0
    for i in range ( 1 , n + 1 ) :
        curr = findTetrahedralNumber ( i )
        curr = curr + prev ;
        print ( curr , end = ' ▁ ' )
        prev = curr
n = 10
printSeries ( n )

Iterator variables: i
Python program:
def printSeries ( n ) :
    for i in range ( 1 , n + 1 ) :
        num = int ( i * ( i + 1 ) * ( i + 2 ) * ( i + 3 ) // 24 )
        print ( num , end = ' ▁ ' ) ;
n = 10
printSeries ( n )

Iterator variables: i
Python program:
def No_Of_Pairs ( N ) :
    i = 1 ;
    while ( ( i * i * i ) + ( 2 * i * i ) + i <= N ) :
        i += 1 ;
    return ( i - 1 ) ;
def print_pairs ( pairs ) :
    i = 1 ;
    mul = 0 ;
    for i in range ( 1 , pairs + 1 ) :
        mul = i * ( i + 1 ) ;
        print ( " Pair ▁ no . " , i , " ▁ - - > ▁ ( " , ( mul * i ) , " , ▁ " , mul * ( i + 1 ) , " ) " ) ;
N = 500 ;
i = 1 ;
pairs = No_Of_Pairs ( N ) ;
print ( " No . ▁ of ▁ pairs ▁ = ▁ " , pairs ) ;
print_pairs ( pairs ) ;

Iterator variables: i
Python program:
def findTriangularNumber ( n ) :
    return ( n * ( n + 1 ) ) / 2
def printSeries ( n ) :
    prev = 0
    for i in range ( 1 , n + 1 ) :
        curr = findTriangularNumber ( i )
        curr = int ( curr + prev )
        print ( curr , end = ' ▁ ' )
        prev = curr
n = 10
printSeries ( n )

Iterator variables: i
Python program:
def printSeries ( n ) :
    for i in range ( 1 , n + 1 ) :
        num = i * ( i + 1 ) * ( i + 2 ) // 6
        print ( num , end = ' ▁ ' )
n = 10
printSeries ( n )

Iterator variables: i
Python program:
def count_even_odd ( min , max , steps ) :
    beven = True
    aeven = False
    n = 2
    for i in range ( 0 , n ) :
        a = steps [ i ] [ 0 ]
        b = steps [ i ] [ 1 ]
        if ( not ( aeven or a & 1 ) ) :
            aeven = True
        if ( beven ) :
            if ( b & 1 ) :
                beven = False
        elif ( not ( a & 1 ) ) :
            if ( not ( b & 1 ) ) :
                beven = True
        else :
            if ( b & 1 ) :
                beven = True
    if ( beven ) :
        even = ( int ( max / 2 ) - int ( ( min - 1 ) / 2 ) )
        odd = 0
    else :
        even = ( int ( max / 2 ) - int ( ( min - 1 ) / 2 ) )
        odd = 0
    if ( not ( beven ^ aeven ) ) :
        even += ( max - min + 1 - int ( max / 2 ) + int ( ( min - 1 ) / 2 ) )
    else :
        odd += ( max - min + 1 - int ( max / 2 ) + int ( ( min - 1 ) / 2 ) )
    print ( " even ▁ = ▁ " , even , " , ▁ odd ▁ = ▁ " , odd , sep = " " )
min = 1
max = 4
steps = [ [ 1 , 2 ] , [ 3 , 4 ] ]
count_even_odd ( min , max , steps )

Index/key variables: i
Iterator variables: i
Boolean variables: aeven, beven
Python program:
def minimumOperations ( a , n ) :
    mp = dict ( )
    for i in range ( n ) :
        if a [ i ] in mp . keys ( ) :
            mp [ a [ i ] ] += 1
        else :
            mp [ a [ i ] ] = 1
    count = 0
    for it in mp :
        if ( mp [ it ] > 1 ) :
            count += mp [ it ] - 1
    return count
a = [ 2 , 1 , 2 , 3 , 3 , 4 , 3 ]
n = len ( a )
print ( minimumOperations ( a , n ) )

Index/key variables: i, it
Accumulator variables: count
Iterator variables: i, it
Python program:
import math
def fibonacci ( n ) :
    for i in range ( n ) :
        fib = ( ( pow ( ( 1 + math . sqrt ( 5 ) ) , i ) - pow ( ( 1 - math . sqrt ( 5 ) ) , i ) ) / ( pow ( 2 , i ) * math . sqrt ( 5 ) ) ) ;
        print ( int ( fib ) , end = " ▁ " ) ;
n = 8 ;
fibonacci ( n ) ;

Iterator variables: i
Python program:
MAX = 100 ;
def findNature ( a , b , n ) :
    seq = [ 0 ] * MAX ;
    seq [ 0 ] = a ;
    seq [ 1 ] = b ;
    for i in range ( 2 , n + 1 ) :
        seq [ i ] = seq [ i - 1 ] + seq [ i - 2 ] ;
    return ( seq [ n ] & 1 ) ;
a = 2 ;
b = 4 ;
n = 3 ;
if ( findNature ( a , b , n ) ) :
    print ( " Odd " ) ;
else :
    print ( " Even " ) ;

Index/key variables: i, n
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a ;
    return gcd ( b , a % b ) ;
def maxDivisorRange ( a , b , l , h ) :
    g = gcd ( a , b ) ;
    res = - 1 ;
    i = l ;
    while ( i * i <= g and i <= h ) :
        if ( g % i == 0 ) :
            res = max ( res , max ( i , g / i ) ) ;
        i += 1 ;
    return int ( res ) ;
if __name__ == " _ _ main _ _ " :
    a = 3 ;
    b = 27 ;
    l = 1 ;
    h = 5 ;
    print ( maxDivisorRange ( a , b , l , h ) ) ;

Accumulator variables: i
Python program:
def checksum ( n ) :
    if n == 0 :
        print ( " - 2 ▁ - 1 ▁ 0 ▁ 1 ▁ 2" )
        return 0
    inc = 0
    if n > 0 :
        inc = 1
    else :
        inc = - 1
    for i in range ( 0 , n - 3 , inc ) :
        if i + i + 1 + i + 2 + i + 3 + i + 4 == n :
            print ( i , " ▁ " , i + 1 , " ▁ " , i + 2 , " ▁ " , i + 3 , " ▁ " , i + 4 )
            return 0
    print ( " - 1" )
n = 15
checksum ( n )

Iterator variables: i
Python program:
N = 1000001
visited = [ 0 ] * N ;
goesTo = [ 0 ] * N ;
def dfs ( i ) :
    if ( visited [ i ] == 1 ) :
        return 0 ;
    visited [ i ] = 1 ;
    x = dfs ( goesTo [ i ] ) ;
    return ( x + 1 ) ;
def noOfTranspositions ( P , n ) :
    for i in range ( 1 , n + 1 ) :
        visited [ i ] = 0 ;
    for i in range ( n ) :
        goesTo [ P [ i ] ] = i + 1 ;
    transpositions = 0 ;
    for i in range ( 1 , n + 1 ) :
        if ( visited [ i ] == 0 ) :
            ans = dfs ( i ) ;
            transpositions += ans - 1 ;
    return transpositions ;
if __name__ == " _ _ main _ _ " :
    permutation = [ 5 , 1 , 4 , 3 , 2 ] ;
    n = len ( permutation ) ;
    print ( noOfTranspositions ( permutation , n ) ) ;

Index/key variables: i
Accumulator variables: transpositions
Iterator variables: i
Python program:
def sumOfSeries ( n ) :
    ans = 0
    for i in range ( 1 , n + 1 ) :
        ans = ans + i * i * i * i
    return ans
n = 4
print ( sumOfSeries ( n ) )

Iterator variables: i
Python program:
def factorial ( n ) :
    res = 1
    for i in range ( 2 , n + 1 ) :
        res = res * i
    return res
def calculateSeries ( n ) :
    return factorial ( n + 1 ) - 1
n = 3
print ( calculateSeries ( n ) )

Iterator variables: i
Python program:
import math
def factorial ( n ) :
    res = 1
    i = 2
    for i in ( n + 1 ) :
        res = res * i
    return res
def calculateSeries ( n ) :
    return ( 2 + ( n * n + n - 2 ) * math . factorial ( n + 1 ) )
n = 3
print ( calculateSeries ( n ) )

Iterator variables: i
Python program:
def findSum ( n ) :
    summ = 0
    for i in range ( 1 , n + 1 ) :
        summ = ( summ + ( ( i * ( i + 1 ) * ( 2 * i + 1 ) ) / 6 ) )
    return summ
n = 3
print ( int ( findSum ( n ) ) )

Iterator variables: i
Python program:
N = 4
def checkHankelMatrix ( n , m ) :
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            if ( i + j < n ) :
                if ( m [ i ] [ j ] != m [ i + j ] [ 0 ] ) :
                    return False
            else :
                if ( m [ i ] [ j ] != m [ i + j - n + 1 ] [ n - 1 ] ) :
                    return False
    return True
n = 4
m = [ [ 1 , 2 , 3 , 5 , ] , [ 2 , 3 , 5 , 8 , ] , [ 3 , 5 , 8 , 0 , ] , [ 5 , 8 , 0 , 9 ] ]
( print ( " Yes " ) if checkHankelMatrix ( n , m ) else print ( " No " ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import math
def isPower ( n ) :
    for x in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) :
        f = math . log ( n ) / math . log ( x ) ;
        if ( ( f - int ( f ) ) == 0.0 ) :
            return True ;
    return False ;
for i in range ( 2 , 100 ) :
    if ( isPower ( i ) ) :
        print ( i , end = " ▁ " ) ;

Iterator variables: i, x
Python program:
N = 100
digitSum = [ 0 ] * N
factorDigitSum = [ 0 ] * N
def sumOddDigit ( ) :
    global N , digitSum , factorDigitSum
    for i in range ( 1 , N ) :
        digitSum [ i ] = ( digitSum [ int ( i / 10 ) ] + int ( i & 1 ) * ( i % 10 ) )
def sumFactor ( ) :
    global N , digitSum , factorDigitSum
    j = 0
    for i in range ( 1 , N ) :
        j = i
        while ( j < N ) :
            factorDigitSum [ j ] = ( factorDigitSum [ j ] + digitSum [ i ] )
            j = j + i
def wrapper ( q , n ) :
    global N , digitSum , factorDigitSum
    for i in range ( 0 , N ) :
        digitSum [ i ] = 0
        factorDigitSum [ i ] = 0
    sumOddDigit ( )
    sumFactor ( )
    for i in range ( 0 , q ) :
        print ( " { } ▁ " . format ( factorDigitSum [ n [ i ] ] ) , end = " " )
q = 2
n = [ 10 , 36 ]
wrapper ( q , n )

Index/key variables: i, j
Iterator variables: i
Python program:
def number_of_digits ( n ) :
    i = 4
    res = 1
    sum = 0
    while ( True ) :
        i *= 4
        res += 1
        sum += i
        if ( sum >= n ) :
            break
    return res
n = 21
print ( number_of_digits ( n ) )

Accumulator variables: i, res, sum
Python program:
def checkVantieghemsTheorem ( limit ) :
    prod = 1
    for n in range ( 2 , limit ) :
        if n == 2 :
            print ( 2 , " is ▁ prime " )
        if ( ( ( prod - n ) % ( ( 1 << n ) - 1 ) ) == 0 ) :
            print ( n , " is ▁ prime " )
        prod *= ( ( 1 << n ) - 1 )
checkVantieghemsTheorem ( 10 )

Accumulator variables: prod
Iterator variables: n
Python program:
mod = 1000000007
N = 1000005
fact = [ 0 ] * N
invfact = [ 0 ] * N
def check ( x , a , b ) :
    if ( x == 0 ) :
        return 0
    while ( x ) :
        if ( x % 10 != a and x % 10 != b ) :
            return 0
        x //= 10
    return 1
def modInverse ( a , m ) :
    m0 = m
    y = 0
    x = 1
    if ( m == 1 ) :
        return 0
    while ( a > 1 ) :
        q = a // m
        t = m
        m = a % m
        a = t
        t = y
        y = x - q * y
        x = t
    if ( x < 0 ) :
        x += m0
    return x
def pregenFact ( ) :
    fact [ 0 ] = fact [ 1 ] = 1
    for i in range ( 1 , 1000001 ) :
        fact [ i ] = fact [ i - 1 ] * i % mod
def pregenInverse ( ) :
    invfact [ 0 ] = invfact [ 1 ] = 1
    invfact [ 1000000 ] = modInverse ( fact [ 1000000 ] , mod )
    for i in range ( 999999 , 0 , - 1 ) :
        invfact [ i ] = ( ( invfact [ i + 1 ] * ( i + 1 ) ) % mod )
def comb ( big , small ) :
    return ( fact [ big ] * invfact [ small ] % mod * invfact [ big - small ] % mod )
def count ( a , b , n ) :
    pregenFact ( )
    pregenInverse ( )
    if ( a == b ) :
        return ( check ( a * n , a , b ) )
    ans = 0
    for i in range ( n + 1 ) :
        if ( check ( i * a + ( n - i ) * b , a , b ) ) :
            ans = ( ans + comb ( n , i ) ) % mod
    return ans
if __name__ == " _ _ main _ _ " :
    a = 3
    b = 4
    n = 11028
    print ( count ( a , b , n ) )

Index/key variables: big, i, small
Accumulator variables: x
Iterator variables: i
Python program:
def magicOfSequence ( N ) :
    sum = 0
    for i in range ( 1 , N + 1 ) :
        sum += ( i * i * i + i * 2 )
    return sum ;
N = 4
print ( magicOfSequence ( N ) )

Accumulator variables: sum
Iterator variables: i
Python program:
def isPossibleToZero ( a , n ) :
    even = 0 ;
    odd = 0 ;
    for i in range ( n ) :
        if ( i & 1 ) :
            odd += a [ i ] ;
        else :
            even += a [ i ] ;
    return ( odd == even ) ;
arr = [ 0 , 1 , 1 , 0 ] ;
n = len ( arr ) ;
if ( isPossibleToZero ( arr , n ) ) :
    print ( " YES " ) ;
else :
    print ( " NO " ) ;

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
PI = 3.142 ;
def cosXSertiesSum ( x , n ) :
    x = x * ( PI / 180.0 ) ;
    res = 1 ;
    sign = 1 ;
    fact = 1 ;
    pow = 1 ;
    for i in range ( 1 , 5 ) :
        sign = sign * ( - 1 ) ;
        fact = fact * ( 2 * i - 1 ) * ( 2 * i ) ;
        pow = pow * x * x ;
        res = res + sign * pow / fact ;
    return res ;
x = 50 ;
n = 5 ;
print ( round ( cosXSertiesSum ( x , 5 ) , 6 ) ) ;

Iterator variables: i
Python program:
def solve ( n , base ) :
    result = 0
    while ( n > 0 ) :
        remainder = n % base
        result = result + remainder
        n = int ( n / base )
    return result
def printSumsOfDigits ( n ) :
    for base in range ( 2 , n ) :
        print ( solve ( n , base ) , end = " ▁ " )
n = 8
printSumsOfDigits ( n )

Iterator variables: base
Python program:
import math
def perfectSquare ( s ) :
    n = len ( s )
    ans = - 1
    num = " "
    for i in range ( 1 , ( 1 << n ) ) :
        str = " "
        for j in range ( 0 , n ) :
            if ( ( i >> j ) & 1 ) :
                str = str + s [ j ]
        if ( str [ 0 ] != '0' ) :
            temp = 0 ;
            for j in range ( 0 , len ( str ) ) :
                temp = ( temp * 10 + ( ord ( str [ j ] ) - ord ( '0' ) ) )
            k = int ( math . sqrt ( temp ) )
            if ( k * k == temp ) :
                if ( ans < len ( str ) ) :
                    ans = len ( str )
                    num = str
    if ( ans == - 1 ) :
        return ans
    else :
        print ( " { } ▁ " . format ( num ) , end = " " )
        return n - ans
print ( perfectSquare ( "8314" ) )
print ( perfectSquare ( "753" ) ) ;

Index/key variables: j
Iterator variables: i, j
Python program:
def gen ( n , r ) :
    a = r [ - 1 ]
    a += 1
    for i in range ( 1 , n + 1 ) :
        r . append ( a )
        a += 2
    return r
def conell ( n ) :
    res = [ ]
    k = 1
    res . append ( 0 )
    while 1 :
        res = gen ( k , res )
        k += 1
        j = len ( res ) - 1
        while j != n and j + k > n :
            k -= 1
        if j >= n :
            break
    res . remove ( res [ 0 ] )
    return res
if __name__ == " _ _ main _ _ " :
    n = 10
    print ( " The ▁ first ▁ % d ▁ terms ▁ are " % n )
    res = conell ( n )
    for i in range ( len ( res ) ) :
        print ( res [ i ] , end = " ▁ " )
    print ( )

Index/key variables: i
Accumulator variables: a, k, r
Iterator variables: i
Python program:
def factorial ( n ) :
    res = 1 ;
    for i in range ( 2 , n + 1 ) :
        res *= i ;
    return res ;
def printNComposite ( n ) :
    fact = factorial ( n + 1 ) ;
    for i in range ( 2 , n + 2 ) :
        print ( fact + i , end = " ▁ " ) ;
n = 4 ;
printNComposite ( n ) ;

Accumulator variables: res
Iterator variables: i