dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def division ( num1 , num2 ) :
    if ( num1 == 0 ) : return 0
    if ( num2 == 0 ) : return INT_MAX
    negResult = 0
    if ( num1 < 0 ) :
        num1 = - num1
        if ( num2 < 0 ) :
            num2 = - num2
        else :
            negResult = true
    elif ( num2 < 0 ) :
        num2 = - num2
        negResult = true
    quotient = 0
    while ( num1 >= num2 ) :
        num1 = num1 - num2
        quotient += 1
    if ( negResult ) :
        quotient = - quotient
    return quotient
num1 = 13 ; num2 = 2
print ( division ( num1 , num2 ) )

Accumulator variables: quotient
Python program:
def Nonagonal ( n ) :
    for i in range ( 1 , n + 1 ) :
        print ( int ( i * ( 7 * i - 5 ) / 2 ) , end = " ▁ " )
n = 10
Nonagonal ( n )

Iterator variables: i
Python program:
import math
def isPrime ( n ) :
    if n <= 1 :
        return False
    if n <= 3 :
        return True
    if n % 2 == 0 or n % 3 == 0 :
        return False
    for i in range ( 5 , int ( math . sqrt ( n ) + 1 ) , 6 ) :
        if n % i == 0 or n % ( i + 2 ) == 0 :
            return False
    return True
def twinPrime ( n1 , n2 ) :
    return ( isPrime ( n1 ) and isPrime ( n2 ) and abs ( n1 - n2 ) == 2 )
n1 = 137
n2 = 139
if twinPrime ( n1 , n2 ) :
    print ( " Twin ▁ Prime " )
else :
    print ( " Not ▁ Twin ▁ Prime " )

Iterator variables: i
Python program:
def motzkin ( n ) :
    dp = [ None ] * ( n + 1 )
    dp [ 0 ] = dp [ 1 ] = 1 ;
    i = 2
    while i <= n :
        dp [ i ] = ( ( 2 * i + 1 ) * dp [ i - 1 ] + ( 3 * i - 3 ) * dp [ i - 2 ] ) / ( i + 2 ) ;
        i = i + 1
    return dp [ n ] ;
n = 8
print ( motzkin ( n ) )

Index/key variables: i, n
Python program:
from __future__ import division
def sumOfSeries ( a , num ) :
    res = 0
    prev = 1
    for i in range ( 1 , n + 1 ) :
        prev *= ( a / i )
        res = res + prev
    return res
n = 5
a = 2
print ( round ( sumOfSeries ( a , n ) , 4 ) )

Accumulator variables: prev
Iterator variables: i
Python program:
def printTrib ( n ) :
    dp = [ 0 ] * n
    dp [ 0 ] = dp [ 1 ] = 0 ;
    dp [ 2 ] = 1 ;
    for i in range ( 3 , n ) :
        dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + dp [ i - 3 ] ;
    for i in range ( 0 , n ) :
        print ( dp [ i ] , " ▁ " , end = " " )
n = 10
printTrib ( n )

Index/key variables: i
Iterator variables: i
Python program:
def multiply ( T , M ) :
    a = ( T [ 0 ] [ 0 ] * M [ 0 ] [ 0 ] + T [ 0 ] [ 1 ] * M [ 1 ] [ 0 ] + T [ 0 ] [ 2 ] * M [ 2 ] [ 0 ] )
    b = ( T [ 0 ] [ 0 ] * M [ 0 ] [ 1 ] + T [ 0 ] [ 1 ] * M [ 1 ] [ 1 ] + T [ 0 ] [ 2 ] * M [ 2 ] [ 1 ] )
    c = ( T [ 0 ] [ 0 ] * M [ 0 ] [ 2 ] + T [ 0 ] [ 1 ] * M [ 1 ] [ 2 ] + T [ 0 ] [ 2 ] * M [ 2 ] [ 2 ] )
    d = ( T [ 1 ] [ 0 ] * M [ 0 ] [ 0 ] + T [ 1 ] [ 1 ] * M [ 1 ] [ 0 ] + T [ 1 ] [ 2 ] * M [ 2 ] [ 0 ] )
    e = ( T [ 1 ] [ 0 ] * M [ 0 ] [ 1 ] + T [ 1 ] [ 1 ] * M [ 1 ] [ 1 ] + T [ 1 ] [ 2 ] * M [ 2 ] [ 1 ] )
    f = ( T [ 1 ] [ 0 ] * M [ 0 ] [ 2 ] + T [ 1 ] [ 1 ] * M [ 1 ] [ 2 ] + T [ 1 ] [ 2 ] * M [ 2 ] [ 2 ] )
    g = ( T [ 2 ] [ 0 ] * M [ 0 ] [ 0 ] + T [ 2 ] [ 1 ] * M [ 1 ] [ 0 ] + T [ 2 ] [ 2 ] * M [ 2 ] [ 0 ] )
    h = ( T [ 2 ] [ 0 ] * M [ 0 ] [ 1 ] + T [ 2 ] [ 1 ] * M [ 1 ] [ 1 ] + T [ 2 ] [ 2 ] * M [ 2 ] [ 1 ] )
    i = ( T [ 2 ] [ 0 ] * M [ 0 ] [ 2 ] + T [ 2 ] [ 1 ] * M [ 1 ] [ 2 ] + T [ 2 ] [ 2 ] * M [ 2 ] [ 2 ] )
    T [ 0 ] [ 0 ] = a
    T [ 0 ] [ 1 ] = b
    T [ 0 ] [ 2 ] = c
    T [ 1 ] [ 0 ] = d
    T [ 1 ] [ 1 ] = e
    T [ 1 ] [ 2 ] = f
    T [ 2 ] [ 0 ] = g
    T [ 2 ] [ 1 ] = h
    T [ 2 ] [ 2 ] = i
def power ( T , n ) :
    if ( n == 0 or n == 1 ) :
        return ;
    M = [ [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] , [ 0 , 1 , 0 ] ]
    power ( T , n // 2 )
    multiply ( T , T )
    if ( n % 2 ) :
        multiply ( T , M )
def tribonacci ( n ) :
    T = [ [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] , [ 0 , 1 , 0 ] ]
    if ( n == 0 or n == 1 ) :
        return 0
    else :
        power ( T , n - 2 )
    return T [ 0 ] [ 0 ]
if __name__ == " _ _ main _ _ " :
    n = 10
    for i in range ( n ) :
        print ( tribonacci ( i ) , end = " ▁ " )
    print ( )

Iterator variables: i
Python program:
import math
def geometricMean ( arr , n ) :
    sum = 0 ;
    for i in range ( n ) :
        sum = sum + math . log ( arr [ i ] ) ;
    sum = sum / n ;
    return math . exp ( sum ) ;
arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ;
n = len ( arr ) ;
print ( geometricMean ( arr , n ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def storeDigitCounts ( n , Hash ) :
    while n > 0 :
        Hash [ n % 10 ] += 1
        n //= 10
def rearrange ( n ) :
    hash_n = [ 0 ] * 10
    storeDigitCounts ( n , hash_n )
    for mult in range ( 2 , 10 ) :
        curr = n * mult
        hash_curr = [ 0 ] * 10
        storeDigitCounts ( curr , hash_curr )
        if hash_n == hash_curr :
            return curr
    return - 1
if __name__ == " _ _ main _ _ " :
    n = 10035
    print ( rearrange ( n ) )

Accumulator variables: n
Iterator variables: mult
Python program:
def count ( x , y ) :
    m = dict ( )
    while x % y != 0 :
        x %= y
        ans += 1
        if x in m :
            return - 1
        m [ x ] = 1
        x *= 10
    return ans
if __name__ == " _ _ main _ _ " :
    res = count ( 1 , 2 )
    print ( " INF " ) if res == - 1 else print ( res )
    res = count ( 5 , 3 )
    print ( " INF " ) if res == - 1 else print ( res )
    res = count ( 3 , 5 )
    print ( " INF " ) if res == - 1 else print ( res )

Index/key variables: x
Accumulator variables: ans
Python program:
def divCount ( n ) :
    hh = [ 1 ] * ( n + 1 ) ;
    p = 2 ;
    while ( ( p * p ) < n ) :
        if ( hh [ p ] == 1 ) :
            for i in range ( ( p * 2 ) , n , p ) :
                hh [ i ] = 0 ;
        p += 1 ;
    total = 1 ;
    for p in range ( 2 , n + 1 ) :
        if ( hh [ p ] == 1 ) :
            count = 0 ;
            if ( n % p == 0 ) :
                while ( n % p == 0 ) :
                    n = int ( n / p ) ;
                    count += 1 ;
                total *= ( count + 1 ) ;
    return total ;
n = 24 ;
print ( divCount ( n ) ) ;

Index/key variables: i, p
Accumulator variables: count, total
Iterator variables: i, p
Python program:
def maxPrimefactorNum ( N ) :
    arr = [ 0 ] * ( N + 1 ) ;
    i = 2 ;
    while ( i * i <= N ) :
        if ( arr [ i ] > 0 ) :
            for j in range ( 2 * i , N + 1 , i ) :
                arr [ j ] += 1 ;
        i += 1 ;
        arr [ i ] = 1 ;
    return max ( arr ) ;
N = 40 ;
print ( maxPrimefactorNum ( N ) ) ;

Index/key variables: i, j
Iterator variables: j
Python program:
def nCr ( n , r ) :
    if ( r > n / 2 ) :
        r = n - r ;
    answer = 1 ;
    for i in range ( 1 , r + 1 ) :
        answer *= ( n - r + i ) ;
        answer /= i ;
    return answer ;
def binomialProbability ( n , k , p ) :
    return ( nCr ( n , k ) * pow ( p , k ) * pow ( 1 - p , n - k ) ) ;
n = 10 ;
k = 5 ;
p = 1.0 / 3 ;
probability = binomialProbability ( n , k , p ) ;
print ( " Probability ▁ of " , k , " heads ▁ when ▁ a ▁ coin ▁ is ▁ tossed " , end = " ▁ " ) ;
print ( n , " times ▁ where ▁ probability ▁ of ▁ each ▁ head ▁ is " , round ( p , 6 ) ) ;
print ( " is ▁ = ▁ " , round ( probability , 6 ) ) ;

Accumulator variables: answer
Iterator variables: i
Python program:
def findMaxGCD ( arr , n ) :
    high = 0
    for i in range ( 0 , n ) :
        high = max ( high , arr [ i ] )
    count = [ 0 ] * ( high + 1 )
    for i in range ( 0 , n ) :
        count [ arr [ i ] ] += 1
    counter = 0
    for i in range ( high , 0 , - 1 ) :
        j = i
        while ( j <= high ) :
            if ( count [ j ] > 0 ) :
                counter += count [ j ]
            j += i
            if ( counter == 2 ) :
                return i
        counter = 0
arr = [ 1 , 2 , 4 , 8 , 8 , 12 ]
n = len ( arr )
print ( findMaxGCD ( arr , n ) )

Index/key variables: i, j
Accumulator variables: counter
Iterator variables: i
Python program:
def CountPairs ( n ) :
    k = n
    imin = 1
    ans = 0
    while ( imin <= n ) :
        imax = n / k
        ans += k * ( imax - imin + 1 )
        imin = imax + 1
        k = n / imin
    return ans
print ( CountPairs ( 1 ) )
print ( CountPairs ( 2 ) )
print ( CountPairs ( 3 ) )

Accumulator variables: ans
Python program:
def powermod ( x , y , p ) :
    while ( y > 0 ) :
        if ( ( y & 1 ) > 0 ) :
            res = ( res * x ) % p ;
        x = ( x * x ) % p ;
    return res ;
def modInverse ( a , m ) :
    m0 = m ;
    x0 = 0 ;
    x1 = 1 ;
    if ( m == 1 ) :
        return 0 ;
    while ( a > 1 ) :
        q = int ( a / m ) ;
        t = m ;
        m = a % m ;
        a = t ;
        t = x0 ;
        x0 = x1 - q * x0 ;
        x1 = t ;
    if ( x1 < 0 ) :
        x1 += m0 ;
    return x1 ;
def evaluteExpression ( n ) :
    firstsum = 0 ;
    mod = 10 ;
    i = 2 ;
    j = 0 ;
    while ( ( 1 << j ) <= n ) :
        firstsum = ( firstsum + i ) % mod ;
        i *= i ;
        j += 1 ;
    secondsum = ( powermod ( 4 , n + 1 , mod ) - 1 ) * modInverse ( 3 , mod ) ;
    return ( firstsum * secondsum ) % mod ;
n = 3 ;
print ( evaluteExpression ( n ) ) ;
n = 10 ;
print ( evaluteExpression ( n ) ) ;

Accumulator variables: i, j
Python program:
def PowerOFPINnfactorial ( n , p ) :
    ans = 0
    temp = p
    while ( temp <= n ) :
        ans += n / temp
        temp = temp * p
    return int ( ans )
print ( PowerOFPINnfactorial ( 4 , 2 ) )

Accumulator variables: ans
Python program:
def decimalToBinary ( N ) :
    B_Number = 0
    cnt = 0
    while ( N != 0 ) :
        rem = N % 2
        c = pow ( 10 , cnt )
        B_Number += rem * c
        N //= 2
        cnt += 1
    return B_Number
N = 17
print ( decimalToBinary ( N ) )

Accumulator variables: B_Number, N, cnt
Python program:
def binaryToDecimal ( n ) :
    num = n ;
    dec_value = 0 ;
    base = 1 ;
    temp = num ;
    while ( temp ) :
        last_digit = temp % 10 ;
        temp = int ( temp / 10 ) ;
        dec_value += last_digit * base ;
        base = base * 2 ;
    return dec_value ;
num = 10101001 ;
print ( binaryToDecimal ( num ) ) ;

Accumulator variables: dec_value
Python program:
def countXorPair ( arr , n ) :
    odd = 0
    even = 0
    for i in range ( n ) :
        if arr [ i ] % 2 == 0 :
            even += 1
        else :
            odd += 1
    return odd * even
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 ]
    n = len ( arr )
    print ( countXorPair ( arr , n ) )

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
MAX_ITERATIONS = 20 ;
def isLychrel ( number ) :
    for i in range ( MAX_ITERATIONS ) :
        number = number + reverse ( number ) ;
        if ( isPalindrome ( number ) ) :
            return " false " ;
    return " true " ;
def isPalindrome ( number ) :
    return number == reverse ( number ) ;
def reverse ( number ) :
    reverse = 0 ;
    while ( number > 0 ) :
        remainder = number % 10 ;
        reverse = ( reverse * 10 ) + remainder ;
        number = int ( number / 10 ) ;
    return reverse ;
number = 295 ;
print ( number , " ▁ is ▁ lychrel ? ▁ " , isLychrel ( number ) ) ;

Iterator variables: i
Python program:
import math ;
MAX_ITERATIONS = 10000 ;
def f ( x ) :
    return ( 1 * pow ( x , 3 ) + 2 * x * x + 10 * x - 20 ) ;
def Muller ( a , b , c ) :
    res = 0 ;
    i = 0 ;
    while ( True ) :
        f1 = f ( a ) ; f2 = f ( b ) ; f3 = f ( c ) ;
        d1 = f1 - f3 ;
        d2 = f2 - f3 ;
        h1 = a - c ;
        h2 = b - c ;
        a0 = f3 ;
        a1 = ( ( ( d2 * pow ( h1 , 2 ) ) - ( d1 * pow ( h2 , 2 ) ) ) / ( ( h1 * h2 ) * ( h1 - h2 ) ) ) ;
        a2 = ( ( ( d1 * h2 ) - ( d2 * h1 ) ) / ( ( h1 * h2 ) * ( h1 - h2 ) ) ) ;
        x = ( ( - 2 * a0 ) / ( a1 + abs ( math . sqrt ( a1 * a1 - 4 * a0 * a2 ) ) ) ) ;
        y = ( ( - 2 * a0 ) / ( a1 - abs ( math . sqrt ( a1 * a1 - 4 * a0 * a2 ) ) ) ) ;
        if ( x >= y ) :
            res = x + c ;
        else :
            res = y + c ;
        m = res * 100 ;
        n = c * 100 ;
        m = math . floor ( m ) ;
        n = math . floor ( n ) ;
        if ( m == n ) :
            break ;
        a = b ;
        b = c ;
        c = res ;
        if ( i > MAX_ITERATIONS ) :
            print ( " Root ▁ cannot ▁ be ▁ found ▁ using " , " Muller ' s ▁ method " ) ;
            break ;
        i += 1 ;
    if ( i <= MAX_ITERATIONS ) :
        print ( " The ▁ value ▁ of ▁ the ▁ root ▁ is " , round ( res , 4 ) ) ;
a = 0 ;
b = 1 ;
c = 2 ;
Muller ( a , b , c ) ;

Accumulator variables: i
Python program:
MAX = 100001 ;
p = [ ] ;
def sieve ( ) :
    isPrime = [ 0 ] * ( MAX + 1 ) ;
    for i in range ( 2 , MAX + 1 ) :
        if ( isPrime [ i ] == 0 ) :
            p . append ( i ) ;
            j = 2 ;
            while ( i * j <= MAX ) :
                isPrime [ i * j ] = 1 ;
                j += 1 ;
def phi ( n ) :
    res = n ;
    i = 0 ;
    while ( p [ i ] * p [ i ] <= n ) :
        if ( n % p [ i ] == 0 ) :
            res -= int ( res / p [ i ] ) ;
            while ( n % p [ i ] == 0 ) :
                n = int ( n / p [ i ] ) ;
        i += 1 ;
    if ( n > 1 ) :
        res -= int ( res / n ) ;
    return res ;
sieve ( ) ;
print ( phi ( 11 ) ) ;
print ( phi ( 21 ) ) ;
print ( phi ( 31 ) ) ;
print ( phi ( 41 ) ) ;
print ( phi ( 51 ) ) ;
print ( phi ( 61 ) ) ;
print ( phi ( 91 ) ) ;
print ( phi ( 101 ) ) ;

Index/key variables: i
Accumulator variables: j, p, res
Iterator variables: i
Python program:
import math
def nthprimedigitsnumber ( n ) :
    len = 1 ;
    prev_count = 0 ;
    while ( 1 ) :
        curr_count = ( prev_count + math . pow ( 4 , len ) ) ;
        if ( prev_count < n and curr_count >= n ) :
            break ;
        len += 1 ;
        prev_count = curr_count ;
    for i in range ( 1 , len + 1 ) :
        for j in range ( 1 , 5 ) :
            if ( prev_count + pow ( 4 , len - i ) < n ) :
                prev_count += pow ( 4 , len - i ) ;
            else :
                if ( j == 1 ) :
                    print ( "2" , end = " " ) ;
                elif ( j == 2 ) :
                    print ( "3" , end = " " ) ;
                elif ( j == 3 ) :
                    print ( "5" , end = " " ) ;
                elif ( j == 4 ) :
                    print ( "7" , end = " " ) ;
                break ;
    print ( ) ;
nthprimedigitsnumber ( 10 ) ;
nthprimedigitsnumber ( 21 ) ;

Accumulator variables: len, prev_count
Iterator variables: i, j
Python program:
def factorial ( n ) :
    a = 1
    for i in range ( 2 , n + 1 ) :
        a *= i
    return a
def printRange ( n ) :
    a = factorial ( n + 2 ) + 2
    b = a + n - 1
    print ( " [ " + str ( a ) + " , ▁ " + str ( b ) + " ] " )
n = 3
printRange ( n )

Accumulator variables: a
Iterator variables: i
Python program:
import math
def findMinValue ( arr , n ) :
    arr . sort ( )
    for i in range ( n ) :
        val += ( math . log ( arr [ i ] ) )
    left = arr [ 0 ]
    right = arr [ n - 1 ] + 1
    while ( left <= right ) :
        mid = ( left + right ) // 2
        temp = n * ( math . log ( mid ) )
        if ( val < temp ) :
            ans = mid
            right = mid - 1
        else :
            left = mid + 1
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 2 , 1 , 10 , 6 ]
    n = len ( arr )
    print ( findMinValue ( arr , n ) )

Index/key variables: i
Accumulator variables: val
Iterator variables: i
Python program:
import math ;
def getOccurence ( n , d ) :
    result = 0 ;
    itr = d ;
    while ( itr <= n ) :
        if ( itr % 10 == d ) :
            result += 1 ;
        if ( itr != 0 and math . floor ( itr / 10 ) == d ) :
            result += 1 ;
            itr += 1 ;
        elif ( math . floor ( itr / 10 ) == d - 1 ) :
            itr = itr + ( 10 - d ) ;
        else :
            itr = itr + 10 ;
    return result ;
n = 11 ;
d = 1 ;
print ( getOccurence ( n , d ) ) ;

Accumulator variables: itr, result
Python program:
def multiply ( v , x ) :
    carry = 0
    size = len ( v )
    for i in range ( size ) :
        res = carry + v [ i ] * x
        v [ i ] = res % 10
        carry = res // 10
    while ( carry != 0 ) :
        v . append ( carry % 10 )
        carry //= 10
def findSumOfDigits ( n ) :
    for i in range ( 1 , n + 1 ) :
        multiply ( v , i )
    sum = 0
    size = len ( v )
    for i in range ( size ) :
        sum += v [ i ]
    return sum
if __name__ == " _ _ main _ _ " :
    n = 1000
    print ( findSumOfDigits ( n ) )

Index/key variables: i
Accumulator variables: carry, sum, v
Iterator variables: i
Python program:
def makeOdd ( n ) :
    if n % 2 != 0 :
        return 1 ;
    for i in range ( 2 , n ) :
        if ( n % i == 0 and ( int ) ( n / i ) % 2 == 1 ) :
            return i ;
n = 36 ;
print ( makeOdd ( n ) ) ;

Iterator variables: i
Python program:
def getTotalXorOfSubarrayXors ( arr , N ) :
    if ( N % 2 == 0 ) :
        return 0
    res = 0
    for i in range ( 0 , N , 2 ) :
        res ^= arr [ i ]
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 5 , 2 , 4 , 6 ]
    N = len ( arr )
    print ( getTotalXorOfSubarrayXors ( arr , N ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def countIterations ( arr , n ) :
    oneFound = False ;
    res = 0 ;
    i = 0 ;
    while ( i < n ) :
        if ( arr [ i ] == 1 ) :
            oneFound = True ;
        while ( i < n and arr [ i ] == 1 ) :
            i += 1 ;
        count_zero = 0 ;
        while ( i < n and arr [ i ] == 0 ) :
            count_zero += 1 ;
            i += 1 ;
        if ( oneFound == False and i == n ) :
            return - 1 ;
        curr_count = 0 ;
        if ( i < n and oneFound == True ) :
            if ( ( count_zero & 1 ) == 0 ) :
                curr_count = count_zero // 2 ;
            else :
                curr_count = ( count_zero + 1 ) // 2 ;
            count_zero = 0 ;
        else :
            curr_count = count_zero ;
            count_zero = 0 ;
        res = max ( res , curr_count ) ;
    return res ;
arr = [ 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ;
n = len ( arr ) ;
print ( countIterations ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count_zero
Boolean variables: oneFound
Python program:
if __name__ == ' _ _ main _ _ ' :
    MAX = 100
    arr = [ 0 for i in range ( MAX ) ]
    arr [ 0 ] = 0
    arr [ 1 ] = 1
    for i in range ( 2 , MAX ) :
        arr [ i ] = arr [ i - 1 ] + arr [ i - 2 ]
    print ( " Fibonacci ▁ numbers ▁ divisible ▁ by ▁ their ▁ indexes ▁ are ▁ : " )
    for i in range ( 1 , MAX ) :
        if ( arr [ i ] % i == 0 ) :
            print ( i , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def printConsecutive ( last , first ) :
    print ( first , end = " " )
    first += 1
    for x in range ( first , last + 1 ) :
        print ( " ▁ + " , x , end = " " )
def findConsecutive ( N ) :
    for last in range ( 1 , N ) :
        for first in range ( 0 , last ) :
            if 2 * N == ( last - first ) * ( last + first + 1 ) :
                print ( N , " = ▁ " , end = " " )
                printConsecutive ( last , first + 1 )
                return
    print ( " - 1" )
n = 12
findConsecutive ( n )

Iterator variables: first, last, x
Python program:
def printNthElement ( n ) :
    arr = [ 0 ] * ( n + 1 ) ;
    arr [ 1 ] = 4
    arr [ 2 ] = 7
    for i in range ( 3 , n + 1 ) :
        if ( i % 2 != 0 ) :
            arr [ i ] = arr [ i // 2 ] * 10 + 4
        else :
            arr [ i ] = arr [ ( i // 2 ) - 1 ] * 10 + 7
    return arr [ n ]
n = 6
print ( printNthElement ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
import sys
def findMaxValue ( ) :
    res = 2 ;
    fact = 2 ;
    while ( True ) :
        if ( fact < 0 or fact > sys . maxsize ) :
            break ;
        res += 1 ;
        fact = fact * res ;
    return res - 1 ;
if __name__ == ' _ _ main _ _ ' :
    print ( " Maximum ▁ value ▁ of ▁ integer : " , findMaxValue ( ) ) ;

Accumulator variables: res
Python program:
def func ( a , k , n ) :
    for i in range ( 0 , n ) :
        if ( a [ i ] % k == 0 ) :
            return True
a = [ 14 , 27 , 38 , 76 , 84 ]
k = 19
res = func ( a , k , 5 )
if ( res ) :
    print ( " true " )
else :
    print ( " false " )

Index/key variables: i
Iterator variables: i
Python program:
def tidyNum ( str , len ) :
    for i in range ( len - 2 , - 1 , - 1 ) :
        if ( str [ i ] > str [ i + 1 ] ) :
            str [ i ] -= 1
            for j in range ( i + 1 , len ) :
                str [ j ] = 9
    return str
str = [ 1 , 1 , 3 , 3 , 3 , 4 , 4 , 5 , 5 , 3 , 8 ]
len = len ( str )
num = tidyNum ( str , len )
for i in range ( 0 , len ) :
    print ( str [ i ] , end = " " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findCount ( m , n ) :
    num1 = 0
    for i in range ( 0 , m ) :
        num1 = ( num1 * 10 ) + 9
    num2 = 0
    for i in range ( 0 , ( m - 1 ) ) :
        num2 = ( num2 * 10 ) + 9
    return int ( ( num1 / n ) - ( num2 / n ) )
m = 2 ; n = 6
print ( findCount ( m , n ) )

Iterator variables: i
Python program:
def findNthEvenDigitNumber ( n ) :
    count = 0 ;
    i = 0 ;
    while ( True ) :
        curr = i ;
        isCurrEvenDigit = True ;
        while ( curr != 0 ) :
            if ( curr % 10 == 1 or curr % 10 == 3 or curr % 10 == 5 or curr % 10 == 7 or curr % 10 == 9 ) :
                isCurrEvenDigit = False ;
            curr = curr // 10 ;
        if ( isCurrEvenDigit == True ) :
            count += 1 ;
        if ( count == n ) :
            return i ;
        i += 1 ;
print ( findNthEvenDigitNumber ( 2 ) ) ;
print ( findNthEvenDigitNumber ( 10 ) ) ;

Accumulator variables: count, i
Boolean variables: isCurrEvenDigit
Python program:
def findNthEvenDigitNumber ( n ) :
    if ( n == 1 ) :
        return 0
    v = [ ]
    n = n - 1
    while ( n > 0 ) :
        v . append ( n % 5 )
        n = n // 5
    result = 0
    for i in range ( len ( v ) - 1 , - 1 , - 1 ) :
        result = result * 10
        result = result + v [ i ]
    return 2 * result
if __name__ == " _ _ main _ _ " :
    print ( findNthEvenDigitNumber ( 2 ) )
    print ( findNthEvenDigitNumber ( 10 ) )

Index/key variables: i
Accumulator variables: v
Iterator variables: i
Python program:
def isLeap ( y ) :
    if ( y % 100 != 0 and y % 4 == 0 or y % 400 == 0 ) :
        return True
    return False
def offsetDays ( d , m , y ) :
    offset = d
    switcher = { 10 : 30 , 9 : 31 , 8 : 30 , 7 : 31 , 6 : 31 , 5 : 30 , 4 : 31 , 3 : 30 , 2 : 31 , 1 : 28 , 0 : 31 }
    if ( isLeap ( y ) and m > 1 ) :
        offset += 1
    offset += switcher . get ( m )
    return offset
def revoffsetDays ( offset , y , d , m ) :
    month = [ 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ]
    if ( isLeap ( y ) ) :
        month [ 2 ] = 29
    for i in range ( 1 , 13 ) :
        if ( offset <= month [ i ] ) :
            break
        offset = offset - month [ i ]
    d [ 0 ] = offset
    m [ 0 ] = i + 1
def addDays ( d1 , m1 , y1 , x ) :
    offset1 = offsetDays ( d1 , m1 , y1 )
    if isLeap ( y1 ) :
        remDays = 366 - offset1
    else :
        remDays = 365 - offset1
    if ( x <= remDays ) :
        y2 = y1
        offset2 = offset1 + x
    else :
        x -= remDays
        y2 = y1 + 1
        if isLeap ( y2 ) :
            y2days = 366
        else :
            y2days = 365
        while ( x >= y2days ) :
            x -= y2days
            y2 += 1
            if isLeap ( y2 ) :
                y2days = 366
            else :
                y2days = 365
        offset2 = x
    m2 = [ 0 ]
    d2 = [ 0 ]
    revoffsetDays ( offset2 , y2 , d2 , m2 )
    print ( " d2 ▁ = ▁ " , * d2 , " , ▁ m2 ▁ = ▁ " , * m2 , " , ▁ y2 ▁ = ▁ " , y2 , sep = " " )
d = 14
m = 3
y = 2015
x = 366
addDays ( d , m , y , x )

Index/key variables: i
Accumulator variables: x, y2
Iterator variables: i