dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from math import gcd
def findHcf ( arr , size ) :
    ans = arr [ 0 ] [ 0 ]
    for i in range ( 1 , size , 1 ) :
        ans = gcd ( ans , arr [ i ] [ 0 ] )
    return ( ans )
def findLcm ( arr , size ) :
    ans = arr [ 0 ] [ 1 ]
    for i in range ( 1 , size , 1 ) :
        ans = int ( ( ( ( arr [ i ] [ 1 ] * ans ) ) / ( gcd ( arr [ i ] [ 1 ] , ans ) ) ) )
    return ( ans )
def hcfOfFraction ( arr , size ) :
    hcf_of_num = findHcf ( arr , size )
    lcm_of_deno = findLcm ( arr , size )
    result = [ 0 for i in range ( 2 ) ]
    result [ 0 ] = hcf_of_num
    result [ 1 ] = lcm_of_deno
    i = int ( result [ 0 ] / 2 )
    while ( i > 1 ) :
        if ( ( result [ 1 ] % i == 0 ) and ( result [ 0 ] % i == 0 ) ) :
            result [ 1 ] = int ( result [ 1 ] / i )
            result [ 0 ] = ( result [ 0 ] / i )
    return ( result )
if __name__ == ' _ _ main _ _ ' :
    size = 4
    arr = [ 0 for i in range ( size ) ]
    for i in range ( size ) :
        arr [ i ] = [ 0 for i in range ( 2 ) ]
    arr [ 0 ] [ 0 ] = 9
    arr [ 0 ] [ 1 ] = 10
    arr [ 1 ] [ 0 ] = 12
    arr [ 1 ] [ 1 ] = 25
    arr [ 2 ] [ 0 ] = 18
    arr [ 2 ] [ 1 ] = 35
    arr [ 3 ] [ 0 ] = 21
    arr [ 3 ] [ 1 ] = 40
    result = hcfOfFraction ( arr , size )
    print ( result [ 0 ] , " , " , result [ 1 ] )

Index/key variables: i
Iterator variables: i
Python program:
import math
def SternSequenceFunc ( BrocotSequence , n ) :
    for i in range ( 1 , n ) :
        considered_element = BrocotSequence [ i ]
        precedent = BrocotSequence [ i - 1 ]
        BrocotSequence . append ( considered_element + precedent )
        BrocotSequence . append ( considered_element )
    for i in range ( 0 , 15 ) :
        print ( BrocotSequence [ i ] , end = " ▁ " )
n = 15
BrocotSequence = [ ]
BrocotSequence . append ( 1 )
BrocotSequence . append ( 1 )
SternSequenceFunc ( BrocotSequence , n )

Index/key variables: i
Accumulator variables: BrocotSequence
Iterator variables: i
Python program:
def isRevDiffDivisible ( x , k ) :
    n = x ; m = 0
    while ( x > 0 ) :
        m = m * 10 + x % 10
        x = x // 10
    return ( abs ( n - m ) % k == 0 )
def countNumbers ( l , r , k ) :
    count = 0
    for i in range ( l , r + 1 ) :
        if ( isRevDiffDivisible ( i , k ) ) :
            count = count + 1
    return count
l = 20 ; r = 23 ; k = 6
print ( countNumbers ( l , r , k ) )

Iterator variables: i
Python program:
import math
def nonsquare ( n ) :
    return n + ( int ) ( 0.5 + math . sqrt ( n ) )
def printNonSquare ( n ) :
    for i in range ( 1 , n + 1 ) :
        print ( nonsquare ( i ) , end = " ▁ " )
n = 10
printNonSquare ( n )

Iterator variables: i
Python program:
def getLudic ( n ) :
    ludics = [ ]
    for i in range ( 1 , n + 1 ) :
        ludics . append ( i )
    index = 1
    while ( index != len ( ludics ) ) :
        first_ludic = ludics [ index ]
        remove_index = index + first_ludic
        while ( remove_index < len ( ludics ) ) :
            ludics . remove ( ludics [ remove_index ] )
            remove_index = remove_index + first_ludic - 1
        index += 1
    return ludics
n = 25
print ( getLudic ( n ) )

Index/key variables: index, remove_index
Accumulator variables: ludics
Iterator variables: i
Python program:
def sieve ( n , prime ) :
    p = 2
    while ( p * p <= n ) :
        if ( prime [ p ] == True ) :
            i = p * 2
            while ( i <= n ) :
                prime [ i ] = False
                i = i + p
        p = p + 1
def printPrimeTriplets ( n ) :
    prime = [ True ] * ( n + 1 )
    sieve ( n , prime )
    print ( " The ▁ prime ▁ triplets ▁ from ▁ 1 ▁ to ▁ " , n , " are ▁ : " )
    for i in range ( 2 , n - 6 + 1 ) :
        if ( prime [ i ] and prime [ i + 2 ] and prime [ i + 6 ] ) :
            print ( i , ( i + 2 ) , ( i + 6 ) )
        elif ( prime [ i ] and prime [ i + 4 ] and prime [ i + 6 ] ) :
            print ( i , ( i + 4 ) , ( i + 6 ) )
n = 25
printPrimeTriplets ( n )

Index/key variables: i, p
Iterator variables: i
Python program:
import math
def nearestPerfectSquare ( arr , N ) :
    for i in range ( N ) :
        sr = int ( math . sqrt ( arr [ i ] ) )
        if ( ( sr & 1 ) == ( arr [ i ] & 1 ) ) :
            print ( sr * sr , end = " ▁ " )
        else :
            sr += 1
            print ( sr * sr , end = " ▁ " )
arr = [ 6 , 3 , 2 , 15 ]
N = len ( arr )
nearestPerfectSquare ( arr , N )

Index/key variables: i
Accumulator variables: sr
Iterator variables: i
Python program:
import math
def isPentagonal ( N ) :
    i = 1
    while True :
        M = ( 3 * i * i - i ) / 2
        i += 1
        if ( M >= N ) :
            break
    return ( M == N )
N = 12
if ( isPentagonal ( N ) ) :
    print ( N , end = ' ▁ ' )
    print ( " is ▁ pentagonal ▁ " )
else :
    print ( N , end = ' ▁ ' )
    print ( " is ▁ not ▁ pentagonal " )

Accumulator variables: i
Python program:
def aliquotSum ( n ) :
    sm = 0
    for i in range ( 1 , n ) :
        if ( n % i == 0 ) :
            sm = sm + i
    return sm
n = 12
print ( aliquotSum ( n ) )

Iterator variables: i
Python program:
def func ( x ) :
    return ( float ( 1 ) / ( 1 + x * x ) )
def calculate ( lower_limit , upper_limit , interval_limit ) :
    interval_size = ( float ( upper_limit - lower_limit ) / interval_limit )
    sum = func ( lower_limit ) + func ( upper_limit ) ;
    for i in range ( 1 , interval_limit ) :
        if ( i % 3 == 0 ) :
            sum = sum + 2 * func ( lower_limit + i * interval_size )
        else :
            sum = sum + 3 * func ( lower_limit + i * interval_size )
    return ( ( float ( 3 * interval_size ) / 8 ) * sum )
interval_limit = 10
lower_limit = 1
upper_limit = 10
integral_res = calculate ( lower_limit , upper_limit , interval_limit )
print ( round ( integral_res , 6 ) )

Iterator variables: i
Python program:
def maxArea ( A , Len ) :
    area = 0
    for i in range ( Len ) :
        for j in range ( i + 1 , Len ) :
            area = max ( area , min ( A [ j ] , A [ i ] ) * ( j - i ) )
    return area
a = [ 1 , 5 , 4 , 3 ]
b = [ 3 , 1 , 2 , 4 , 5 ]
len1 = len ( a )
print ( maxArea ( a , len1 ) )
len2 = len ( b )
print ( maxArea ( b , len2 ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def check ( n ) :
    m = n
    while ( n != 0 ) :
        r = n % 10
        if ( r > 0 ) :
            if ( ( m % r ) != 0 ) :
                return False
        n = n // 10
    return True
def count ( l , r ) :
    ans = 0
    for i in range ( l , r + 1 ) :
        if ( check ( i ) ) :
            ans = ans + 1
    return ans
l = 10
r = 20
print ( count ( l , r ) )

Iterator variables: i
Python program:
def sumOfTheSeries ( n ) :
    sum = 0
    for i in range ( 1 , n + 1 ) :
        sum += 1.0 / ( i * ( i + 1 ) ) ;
    return sum
if __name__ == ' _ _ main _ _ ' :
    ans = sumOfTheSeries ( 10 )
    print ( round ( ans , 6 ) )

Accumulator variables: sum
Iterator variables: i
Python program:
import math
def sum ( n ) :
    root = ( int ) ( math . sqrt ( n ) )
    ans = 0
    for i in range ( 1 , root + 1 ) :
        ans = ans + n // i
    ans = 2 * ans - ( root * root )
    return ans
n = 35
print ( sum ( n ) )

Iterator variables: i
Python program:
def sumofsquare ( n ) :
    C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]
    for i in range ( 0 , n + 1 ) :
        for j in range ( 0 , min ( i , n ) + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1
            else :
                C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )
    sum = 0
    for i in range ( 0 , n + 1 ) :
        sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] )
    return sum
n = 4
print ( sumofsquare ( n ) , end = " " )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
import math
def sumOfSeries ( n ) :
    sum = 0
    for i in range ( 1 , n + 1 ) :
        sum = sum + i * i
    return sum
n = 10
print ( sumOfSeries ( n ) )

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

Iterator variables: i
Python program:
import math
def sum_all_divisors ( num ) :
    sum = 0 ;
    for i in range ( 1 , math . floor ( math . sqrt ( num ) ) + 1 ) :
        sum += t1 + t2 ;
    return sum ;
n = 1
sum = sum_all_divisors ( n )
print ( sum )

Accumulator variables: sum
Iterator variables: i
Python program:
def printKPFNums ( A , B , K ) :
    prime = [ True ] * ( B + 1 )
    p_factors = [ 0 ] * ( B + 1 )
    for p in range ( 2 , B + 1 ) :
        if ( p_factors [ p ] == 0 ) :
            for i in range ( p , B + 1 , p ) :
                p_factors [ i ] = p_factors [ i ] + 1
    for i in range ( A , B + 1 ) :
        if ( p_factors [ i ] == K ) :
            print ( i , end = " ▁ " )
A = 14
B = 18
K = 2
printKPFNums ( A , B , K )

Index/key variables: i, p
Iterator variables: i, p
Python program:
from math import sqrt
MAX = 100005
def precompute ( prefix , suffix ) :
    prime = [ True for i in range ( MAX ) ]
    k = int ( sqrt ( MAX ) )
    for i in range ( 2 , k , 1 ) :
        if ( prime [ i ] ) :
            for j in range ( i * i , MAX , i ) :
                prime [ j ] = False
    prefix [ 1 ] = 1
    suffix [ MAX - 1 ] = int ( 1e9 + 7 )
    for i in range ( 2 , MAX , 1 ) :
        if ( prime [ i ] ) :
            prefix [ i ] = i
        else :
            prefix [ i ] = prefix [ i - 1 ]
    i = MAX - 2
    while ( i > 1 ) :
        if ( prime [ i ] ) :
            suffix [ i ] = i
        else :
            suffix [ i ] = suffix [ i + 1 ]
        i -= 1
def query ( prefix , suffix , L , R ) :
    if ( prefix [ R ] < L or suffix [ L ] > R ) :
        return 0
    else :
        return prefix [ R ] - suffix [ L ]
if __name__ == ' _ _ main _ _ ' :
    q = 3
    L = [ 2 , 2 , 24 ]
    R = [ 5 , 2 , 28 ]
    prefix = [ 0 for i in range ( MAX ) ]
    suffix = [ 0 for i in range ( MAX ) ]
    precompute ( prefix , suffix )
    for i in range ( 0 , q , 1 ) :
        print ( query ( prefix , suffix , L [ i ] , R [ i ] ) )

Index/key variables: L, R, i, j
Iterator variables: i, j
Python program:
def SUM ( x , n ) :
    total = 1
    for i in range ( 1 , n + 1 ) :
        total = total + ( ( x ** i ) / i )
    return total
x = 2
n = 5
s = SUM ( x , n )
print ( round ( s , 2 ) )

Iterator variables: i
Python program:
M = 6
N = 7
def preCompute ( mat , prefixCnt ) :
    for i in range ( M ) :
        for j in range ( N ) :
            if ( mat [ i ] [ j ] == 0 ) :
                prefixCnt [ i ] [ j ] = 1
            else :
                prefixCnt [ i ] [ j ] = 0
    for i in range ( M ) :
        for j in range ( 1 , N ) :
            prefixCnt [ i ] [ j ] += prefixCnt [ i ] [ j - 1 ]
    for i in range ( 1 , M ) :
        for j in range ( N ) :
            prefixCnt [ i ] [ j ] += prefixCnt [ i - 1 ] [ j ]
    return prefixCnt
def countQuery ( prefixCnt , pi , pj , qi , qj ) :
    cnt = prefixCnt [ qi ] [ qj ]
    if ( pi > 0 ) :
        cnt -= prefixCnt [ pi - 1 ] [ qj ]
    if ( pj > 0 ) :
        cnt -= prefixCnt [ qi ] [ pj - 1 ]
    if ( pi > 0 and pj > 0 ) :
        cnt += prefixCnt [ pi - 1 ] [ pj - 1 ]
    return cnt
def count0s ( mat , Q , sizeQ ) :
    prefixCnt = [ [ 0 for i in range ( N ) ] for i in range ( M ) ]
    prefixCnt = preCompute ( mat , prefixCnt )
    for i in range ( sizeQ ) :
        print ( countQuery ( prefixCnt , Q [ i ] [ 0 ] , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , Q [ i ] [ 3 ] ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 0 , 1 , 0 , 1 , 1 , 1 , 0 ] , [ 1 , 0 , 1 , 1 , 1 , 0 , 1 ] , [ 1 , 1 , 0 , 0 , 1 , 1 , 0 ] , [ 1 , 1 , 1 , 1 , 1 , 0 , 1 ] , [ 0 , 0 , 1 , 0 , 1 , 1 , 1 ] , [ 1 , 1 , 0 , 1 , 1 , 0 , 1 ] ]
    Q = [ [ 0 , 1 , 3 , 2 ] , [ 2 , 2 , 4 , 5 ] , [ 4 , 3 , 5 , 6 ] ]
    sizeQ = len ( Q )
    count0s ( mat , Q , sizeQ )

Index/key variables: i, j, qi, qj
Iterator variables: i, j
Python program:
import math
def check ( a , b ) :
    c = 0 ;
    while ( a != 0 ) :
        c = c + a % 10 ;
        a = int ( a / 10 ) ;
    return True if ( c == b ) else False ;
def root ( n ) :
    found = False ;
    mx = 1000000000000000001 ;
    for i in range ( 91 ) :
        s = i * i + 4 * n ;
        sq = int ( math . sqrt ( s ) ) ;
        if ( sq * sq == s and check ( int ( ( sq - i ) / 2 ) , i ) ) :
            found = True ;
            mx = min ( mx , int ( ( sq - i ) / 2 ) ) ;
    if ( found ) :
        return mx ;
    else :
        return - 1 ;
n = 110 ;
print ( root ( n ) ) ;

Iterator variables: i
Boolean variables: found
Python program:
def modBigNumber ( num , m ) :
    vec = [ ]
    mod = 0
    for i in range ( 0 , len ( num ) , 1 ) :
        digit = ord ( num [ i ] ) - ord ( '0' )
        mod = mod * 10 + digit
        quo = int ( mod / m )
        vec . append ( quo )
        mod = mod % m
    print ( " Remainder ▁ : " , mod )
    print ( " Quotient ▁ : " , end = " ▁ " )
    zeroflag = 0 ;
    for i in range ( 0 , len ( vec ) , 1 ) :
        if ( vec [ i ] == 0 and zeroflag == 0 ) :
            continue
        zeroflag = 1
        print ( vec [ i ] , end = " " )
    return
if __name__ == ' _ _ main _ _ ' :
    num = "14598499948265358486"
    m = 487
    modBigNumber ( num , m )

Index/key variables: i
Accumulator variables: vec
Iterator variables: i
Python program:
N = 1000001 ;
fourDiv = [ False ] * ( N + 1 ) ;
def fourDistinctFactors ( ) :
    primeAll = [ True ] * ( N + 1 ) ;
    p = 2 ;
    while ( p * p <= N ) :
        if ( primeAll [ p ] == True ) :
            i = p * 2 ;
            while ( i <= N ) :
                primeAll [ i ] = False ;
                i += p ;
        p += 1 ;
    prime = [ ] ;
    for p in range ( 2 , N + 1 ) :
        if ( primeAll [ p ] ) :
            prime . append ( p ) ;
    for i in range ( len ( prime ) ) :
        p = prime [ i ] ;
        if ( 1 * p * p * p <= N ) :
            fourDiv [ p * p * p ] = True ;
        for j in range ( i + 1 , len ( prime ) ) :
            q = prime [ j ] ;
            if ( 1 * p * q > N ) :
                break ;
            fourDiv [ p * q ] = True ;
fourDistinctFactors ( ) ;
num = 10 ;
if ( fourDiv [ num ] ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;
num = 12 ;
if ( fourDiv [ num ] ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;

Index/key variables: i, j, num, p
Accumulator variables: prime
Iterator variables: i, j, p
Python program:
def leonardo ( n ) :
    dp = [ ] ;
    dp . append ( 1 ) ;
    dp . append ( 1 ) ;
    for i in range ( 2 , n + 1 ) :
        dp . append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 ) ;
    return dp [ n ] ;
print ( leonardo ( 3 ) ) ;

Index/key variables: n
Accumulator variables: dp
Iterator variables: i
Python program:
import math
MAX = 100 ;
def Cholesky_Decomposition ( matrix , n ) :
    lower = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ] ;
    for i in range ( n ) :
        for j in range ( i + 1 ) :
            sum1 = 0 ;
            if ( j == i ) :
                for k in range ( j ) :
                    sum1 += pow ( lower [ j ] [ k ] , 2 ) ;
                lower [ j ] [ j ] = int ( math . sqrt ( matrix [ j ] [ j ] - sum1 ) ) ;
            else :
                for k in range ( j ) :
                    sum1 += ( lower [ i ] [ k ] * lower [ j ] [ k ] ) ;
                if ( lower [ j ] [ j ] > 0 ) :
                    lower [ i ] [ j ] = int ( ( matrix [ i ] [ j ] - sum1 ) / lower [ j ] [ j ] ) ;
    print ( " Lower ▁ Triangular TABSYMBOL TABSYMBOL Transpose " ) ;
    for i in range ( n ) :
        for j in range ( n ) :
            print ( lower [ i ] [ j ] , end = " TABSYMBOL " ) ;
        print ( " " , end = " TABSYMBOL " ) ;
        for j in range ( n ) :
            print ( lower [ j ] [ i ] , end = " TABSYMBOL " ) ;
        print ( " " ) ;
n = 3 ;
matrix = [ [ 4 , 12 , - 16 ] , [ 12 , 37 , - 43 ] , [ - 16 , - 43 , 98 ] ] ;
Cholesky_Decomposition ( matrix , n ) ;

Index/key variables: i, j, k
Accumulator variables: sum1
Iterator variables: i, j, k
Python program:
def findValue ( arr , n ) :
    ans = 0 ;
    for i in range ( n ) :
        for j in range ( n ) :
            ans = ans if ans > ( abs ( arr [ i ] - arr [ j ] ) + abs ( i - j ) ) else ( abs ( arr [ i ] - arr [ j ] ) + abs ( i - j ) ) ;
    return ans ;
arr = [ 1 , 2 , 3 , 1 ] ;
n = len ( arr ) ;
print ( findValue ( arr , n ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findValue ( arr , n ) :
    a = [ ]
    b = [ ]
    for i in range ( n ) :
        a . append ( arr [ i ] + i )
        b . append ( arr [ i ] - i )
    x = a [ 0 ]
    y = a [ 0 ]
    for i in range ( n ) :
        if ( a [ i ] > x ) :
            x = a [ i ]
        if ( a [ i ] < y ) :
            y = a [ i ]
    ans1 = ( x - y )
    x = b [ 0 ]
    y = b [ 0 ]
    for i in range ( n ) :
        if ( b [ i ] > x ) :
            x = b [ i ]
        if ( b [ i ] < y ) :
            y = b [ i ]
    ans2 = ( x - y )
    return max ( ans1 , ans2 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 1 ]
    n = len ( arr )
    print ( findValue ( arr , n ) )

Index/key variables: i
Accumulator variables: a, b
Iterator variables: i
Python program:
def countsubarray ( array , n , k ) :
    count = 0
    for i in range ( 0 , n ) :
        if array [ i ] < k :
            count += 1
        mul = array [ i ]
        for j in range ( i + 1 , n ) :
            mul = mul * array [ j ]
            if mul < k :
                count += 1
            else :
                break
    return count
array = [ 1 , 2 , 3 , 4 ]
k = 10
size = len ( array )
count = countsubarray ( array , size , k )
print ( count , end = " ▁ " )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
MAX = 1000001 ;
factor = [ 0 ] * ( MAX + 1 ) ;
def generatePrimeFactors ( ) :
    factor [ 1 ] = 1 ;
    for i in range ( 2 , MAX ) :
        factor [ i ] = i ;
    for i in range ( 4 , MAX , 2 ) :
        factor [ i ] = 2 ;
    i = 3 ;
    while ( i * i < MAX ) :
        if ( factor [ i ] == i ) :
            j = i * i ;
            while ( j < MAX ) :
                if ( factor [ j ] == j ) :
                    factor [ j ] = i ;
                j += i ;
        i += 1 ;
def calculateNoOFactors ( n ) :
    if ( n == 1 ) :
        return 1 ;
    ans = 1 ;
    dup = factor [ n ] ;
    c = 1 ;
    j = int ( n / factor [ n ] ) ;
    while ( j > 1 ) :
        if ( factor [ j ] == dup ) :
            c += 1 ;
        else :
            dup = factor [ j ] ;
            ans = ans * ( c + 1 ) ;
            c = 1 ;
        j = int ( j / factor [ j ] ) ;
    ans = ans * ( c + 1 ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    generatePrimeFactors ( )
    a = [ 10 , 30 , 100 , 450 , 987 ]
    q = len ( a )
    for i in range ( 0 , q ) :
        print ( calculateNoOFactors ( a [ i ] ) , end = " ▁ " )

Index/key variables: i, j, n
Accumulator variables: c
Iterator variables: i
Python program:
def digit_product_Sum ( N ) :
    a = [ 0 ] * ( N + 1 ) ;
    product = 1 ;
    a [ 0 ] = 1 ;
    for i in range ( 1 , N + 1 ) :
        product = int ( a [ i - 1 ] / 10 ) ;
        if ( product == 0 ) :
            product = 1 ;
        else :
            product = a [ i - 1 ] % 10 ;
        val = int ( a [ i - 1 ] / 10 ) ;
        if ( val == 0 ) :
            val = a [ i - 1 ] ;
        a [ i ] = a [ i - 1 ] + ( val * product ) ;
    for i in range ( N ) :
        print ( a [ i ] , end = " ▁ " ) ;
N = 10 ;
digit_product_Sum ( N ) ;

Index/key variables: i
Iterator variables: i
Python program:
import math
def geometricMean ( arr , n ) :
    product = 1
    for i in range ( 0 , n ) :
        product = product * arr [ i ]
    gm = ( float ) ( math . pow ( product , ( 1 / n ) ) )
    return ( float ) ( gm )
arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ]
n = len ( arr )
print ( ' { 0 : . 6f } ' . format ( geometricMean ( arr , n ) ) )

Index/key variables: i
Iterator variables: i
Python program:
SIZE = 4
def productOfSingelDgt ( n ) :
    if n >= 0 and n <= 9 :
        return True
    prime = [ 2 , 3 , 5 , 7 ]
    i = 0
    while i < SIZE and n > 1 :
        while n % prime [ i ] == 0 :
            n = n / prime [ i ]
        i += 1
    return n == 1
n = 24
if productOfSingelDgt ( n ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Python program:
def maxPrimefactorNum ( N ) :
    if ( N < 2 ) :
        return 0 ;
    arr = [ True ] * ( N + 1 ) ;
    prod = 1 ;
    res = 0 ;
    p = 2 ;
    while ( p * p <= N ) :
        if ( arr [ p ] == True ) :
            for i in range ( p * 2 , N + 1 , p ) :
                arr [ i ] = False ;
            prod *= p ;
            if ( prod > N ) :
                return res ;
            res += 1 ;
        p += 1 ;
    return res ;
N = 500 ;
print ( maxPrimefactorNum ( N ) ) ;

Index/key variables: i, p
Accumulator variables: prod, res
Iterator variables: i
Python program:
def isPalindrome ( n ) :
    divisor = 1
    while ( n / divisor >= 10 ) :
        divisor *= 10
    while ( n != 0 ) :
        leading = n // divisor
        trailing = n % 10
        if ( leading != trailing ) :
            return False
        n = ( n % divisor ) // 10
        divisor = divisor / 100
    return True
if ( isPalindrome ( 1001 ) ) :
    print ( ' Yes , ▁ it ▁ is ▁ palindrome ' )
else :
    print ( ' No , ▁ not ▁ palindrome ' )

Accumulator variables: divisor
Python program:
def NumberofTimes ( s ) :
    temporary_sum = 0
    count = 0
    while ( len ( s ) > 1 ) :
        temporary_sum = 0
        for i in range ( len ( s ) ) :
            temporary_sum += ( ord ( s [ i ] ) - ord ( '0' ) )
        s = str ( temporary_sum )
        count += 1
    return count
if __name__ == " _ _ main _ _ " :
    s = "991"
    print ( NumberofTimes ( s ) )

Index/key variables: i
Accumulator variables: count, temporary_sum
Iterator variables: i
Python program:
def calculateLeaps ( n ) :
    if n == 0 or n == 1 :
        return 1 ;
    else :
        leaps = 0 ;
        for i in range ( 0 , n ) :
            leaps = leaps + calculateLeaps ( i ) ;
        return leaps ;
print ( calculateLeaps ( 4 ) ) ;

Iterator variables: i
Python program:
def power ( x , y , p ) :
    res = 1
    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 printLastKDigits ( a , b , k ) :
    print ( " Last ▁ " + str ( k ) + " ▁ digits ▁ of ▁ " + str ( a ) + " ^ " + str ( b ) , end = " ▁ = ▁ " )
    temp = 1
    for i in range ( 1 , k + 1 ) :
        temp *= 10
    temp = power ( a , b , temp )
    for i in range ( k - numberOfDigits ( temp ) ) :
        print ( "0" )
    if ( temp ) :
        print ( temp )
if __name__ == " _ _ main _ _ " :
    a = 11
    b = 3
    k = 2
    printLastKDigits ( a , b , k )

Accumulator variables: temp, x
Iterator variables: i
Python program:
def totalDigits ( n ) :
    number_of_digits = 0 ;
    for i in range ( 1 , n , 10 ) :
        number_of_digits = ( number_of_digits + ( n - i + 1 ) ) ;
    return number_of_digits ;
n = 13 ;
s = totalDigits ( n ) + 1 ;
print ( s ) ;

Iterator variables: i
Python program:
def numbersWith3Divisors ( n ) :
    prime = [ True ] * ( n + 1 ) ;
    prime [ 0 ] = prime [ 1 ] = False ;
    p = 2 ;
    while ( p * p <= n ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * 2 , n + 1 , p ) :
                prime [ i ] = False ;
        p += 1 ;
    print ( " Numbers ▁ with ▁ 3 ▁ divisors ▁ : " ) ;
    i = 0 ;
    while ( i * i <= n ) :
        if ( prime [ i ] ) :
            print ( i * i , end = " ▁ " ) ;
        i += 1 ;
n = 96 ;
numbersWith3Divisors ( n ) ;

Index/key variables: i, p
Iterator variables: i
Python program:
def decToHexa ( n ) :
    hexaDeciNum = [ '0' ] * 100
    i = 0
    while ( n != 0 ) :
        temp = 0
        temp = n % 16
        if ( temp < 10 ) :
            hexaDeciNum [ i ] = chr ( temp + 48 )
            i = i + 1
        else :
            hexaDeciNum [ i ] = chr ( temp + 55 )
            i = i + 1
        n = int ( n / 16 )
    j = i - 1
    while ( j >= 0 ) :
        print ( ( hexaDeciNum [ j ] ) , end = " " )
        j = j - 1
n = 2545
decToHexa ( n )

Index/key variables: i, j