dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import math
def divisorSum ( N , K ) :
    Sum = 0
    for i in range ( 2 , math . ceil ( math . sqrt ( N ) ) ) :
        if ( N % i == 0 ) :
            Sum += ( i + int ( N / i ) )
    return Sum
def isPrime ( n ) :
    if ( n == 1 or n == 0 ) :
        return False
    if ( n <= 3 ) :
        return True
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return False
    i = 5
    while ( i * i <= n ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return False
        i += 6
    return True
def isHyperPerfect ( N , K ) :
    Sum = divisorSum ( N , K )
    if ( ( 1 + K * ( Sum ) ) == N ) :
        return True
    else :
        return False
N1 = 1570153
K1 = 12
N2 = 321
K2 = 3
if ( isHyperPerfect ( N1 , K1 ) ) :
    print ( N1 , " ▁ is ▁ " , K1 , " - HyperPerfect " , sep = " " )
else :
    print ( N1 , " ▁ is ▁ not ▁ " , K1 , " - HyperPerfect " , sep = " " )
if ( isHyperPerfect ( N2 , K2 ) ) :
    print ( N2 , " ▁ is ▁ " , K2 , " - HyperPerfect " , sep = " " )
else :
    print ( N2 , " ▁ is ▁ not ▁ " , K2 , " - HyperPerfect " , sep = " " )

Accumulator variables: Sum
Iterator variables: i
Python program:
def printWellOrdered ( number , x , k ) :
    if ( k == 0 ) :
        print ( number , end = " ▁ " )
        return
    for i in range ( ( x + 1 ) , 10 ) :
        printWellOrdered ( number * 10 + i , i , k - 1 )
def generateWellOrdered ( k ) :
    printWellOrdered ( 0 , 0 , k )
if __name__ == " _ _ main _ _ " :
    k = 3
    generateWellOrdered ( k )

Iterator variables: i
Python program:
def numberOf2sinRange ( n ) :
    s = " "
    for i in range ( 0 , n + 1 ) :
        s += str ( i )
    return ( list ( s ) . count ( '2' ) )
n = 30
print ( numberOf2sinRange ( n ) )

Accumulator variables: s
Iterator variables: i
Python program:
def count2sinRangeAtDigit ( number , d ) :
    powerOf10 = int ( pow ( 10 , d ) ) ;
    nextPowerOf10 = powerOf10 * 10 ;
    right = number % powerOf10 ;
    roundDown = number - number % nextPowerOf10 ;
    roundup = roundDown + nextPowerOf10 ;
    digit = ( number // powerOf10 ) % 10 ;
    if ( digit < 2 ) :
        return roundDown // 10 ;
    if ( digit == 2 ) :
        return roundDown // 10 + right + 1 ;
    return roundup // 10 ;
def numberOf2sinRange ( number ) :
    s = str ( number ) ;
    len1 = len ( s ) ;
    count = 0 ;
    for digit in range ( len1 ) :
        count += count2sinRangeAtDigit ( number , digit ) ;
    return count ;
print ( numberOf2sinRange ( 22 ) ) ;
print ( numberOf2sinRange ( 100 ) ) ;

Accumulator variables: count
Iterator variables: digit
Python program:
def isTidy ( num ) :
    prev = 10
    while ( num ) :
        rem = num % 10
        num /= 10
        if rem > prev :
            return False
        prev = rem
    return True
num = 1556
if isTidy ( num ) :
    print ( " Yes " )
else :
    print ( " No " )

Accumulator variables: num
Python program:
def squareFree ( n ) :
    cnt = 0 ;
    i = 1 ;
    while ( True ) :
        isSqFree = True ;
        j = 2 ;
        while ( j * j <= i ) :
            if ( i % ( j * j ) == 0 ) :
                isSqFree = False ;
                break ;
            j += 1 ;
        if ( isSqFree == True ) :
            cnt += 1 ;
            if ( cnt == n ) :
                return i ;
        i += 1 ;
    return 0 ;
n = 10 ;
print ( squareFree ( n ) ) ;

Accumulator variables: cnt, i, j
Boolean variables: isSqFree
Python program:
import math as mt
def kFactors ( n , k ) :
    a = list ( )
    while n % 2 == 0 :
        a . append ( 2 )
        n = n // 2
    for i in range ( 3 , mt . ceil ( mt . sqrt ( n ) ) , 2 ) :
        while n % i == 0 :
            n = n / i ;
            a . append ( i )
    if n > 2 :
        a . append ( n )
    if len ( a ) < k :
        print ( " - 1" )
        return
    for i in range ( k - 1 ) :
        print ( a [ i ] , end = " , ▁ " )
    product = 1
    for i in range ( k - 1 , len ( a ) ) :
        product *= a [ i ]
    print ( product )
n , k = 54 , 3
kFactors ( n , k )

Index/key variables: i
Accumulator variables: a, product
Iterator variables: i
Python program:
def nondecdigits ( n ) :
    x = 0
    for x in range ( n , 0 , - 1 ) :
        no = x
        prev_dig = 11
        flag = True
        while ( no != 0 ) :
            if ( prev_dig < no % 10 ) :
                flag = False
                break
            prev_dig = no % 10
            no //= 10
        if ( flag == True ) :
            break
    return x
if __name__ == " _ _ main _ _ " :
    n = 200
    print ( nondecdigits ( n ) )

Accumulator variables: no
Iterator variables: x
Boolean variables: flag
Python program:
def nondecdigits ( s ) :
    m = len ( s ) ;
    a = [ 0 ] * m ;
    for i in range ( m ) :
        a [ i ] = ord ( s [ i ] ) - ord ( '0' ) ;
    level = m - 1 ;
    for i in range ( m - 1 , 0 , - 1 ) :
        if ( a [ i ] < a [ i - 1 ] ) :
            a [ i - 1 ] -= 1 ;
            level = i - 1 ;
    if ( a [ 0 ] != 0 ) :
        for i in range ( level + 1 ) :
            print ( a [ i ] , end = " " ) ;
        for i in range ( level + 1 , m ) :
            print ( "9" , end = " " ) ;
    else :
        for i in range ( 1 , level ) :
            print ( a [ i ] , end = " " ) ;
        for i in range ( level + 1 , m ) :
            print ( "9" , end = " " ) ;
n = "200" ;
nondecdigits ( n ) ;

Index/key variables: i
Iterator variables: i
Python program:
import math
def countDivisors ( n ) :
    cnt = 0
    for i in range ( 1 , ( int ) ( math . sqrt ( n ) ) + 1 ) :
        if ( n % i == 0 ) :
            if ( n / i == i ) :
                cnt = cnt + 1
                cnt = cnt + 2
    return cnt
print ( " Total ▁ distinct ▁ divisors ▁ of ▁ 100 ▁ are ▁ : ▁ " , countDivisors ( 100 ) )

Iterator variables: i
Python program:
import math
def hasEvenNumberOfFactors ( n ) :
    root_n = math . sqrt ( n )
    if ( ( root_n * root_n ) == n ) :
        return False
    return True
def printStatusOfDoors ( n ) :
    for i in range ( 1 , n + 1 ) :
        if ( hasEvenNumberOfFactors ( i ) == True ) :
            print ( " closed " , end = " ▁ " )
        else :
            print ( " open " , end = " ▁ " )
n = 5
printStatusOfDoors ( n )

Iterator variables: i
Python program:
def validate ( n ) :
    for i in range ( 10 ) :
        temp = n ;
        count = 0 ;
        while ( temp ) :
            if ( temp % 10 == i ) :
                count += 1 ;
            if ( count > i ) :
                return - 1 ;
            temp //= 10 ;
    return 1 ;
n = 1552793 ;
geek = " True " if validate ( n ) else " False " ;
print ( geek ) ;

Accumulator variables: count, temp
Iterator variables: i
Python program:
def divisibleBy36 ( num ) :
    l = len ( num )
    if ( l == 0 ) :
        return ( " No " )
    if ( l == 1 and num [ 0 ] != '0' ) :
        return ( " No " )
    two_digit_num = ( ( ( int ) ( num [ l - 2 ] ) ) * 10 + ( int ) ( num [ l - 1 ] ) )
    if ( two_digit_num % 4 != 0 ) :
        return " No "
    sm = 0
    for i in range ( 0 , l ) :
        sm = sm + ( int ) ( num [ i ] )
    if ( sm % 9 != 0 ) :
        return ( " No " )
    return ( " Yes " )
num = "92567812197966231384"
print ( divisibleBy36 ( num ) )

Index/key variables: i
Iterator variables: i
Python program:
def countDigits ( n ) :
    count = 0
    while ( n > 0 ) :
        count += 1
        n = n // 10
    return count
def checkPrime ( n ) :
    if ( n <= 1 ) :
        return - 1
    if ( n <= 3 ) :
        return 0
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return - 1
    i = 5
    while i * i <= n :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return - 1
        i += 6
    return 0
def printPrimePoints ( n ) :
    count = countDigits ( n )
    if ( count == 1 or count == 2 ) :
        print ( " - 1" )
        return
    found = False
    for i in range ( 1 , ( count - 1 ) ) :
        left = n // ( pow ( 10 , count - i ) )
        right = n % ( pow ( 10 , count - i - 1 ) )
        if ( checkPrime ( left ) == 0 and checkPrime ( right ) == 0 ) :
            print ( i , end = " ▁ " )
            found = True
    if ( found == False ) :
        print ( " - 1" )
if __name__ == " _ _ main _ _ " :
    n = 2317
    printPrimePoints ( n )

Accumulator variables: count
Iterator variables: i
Boolean variables: found
Python program:
def gcd ( a , b ) :
    if ( a == 0 ) :
        return b ;
    return gcd ( b % a , a ) ;
def printGenerators ( n ) :
    print ( "1" , end = " ▁ " ) ;
    for i in range ( 2 , n ) :
        if ( gcd ( i , n ) == 1 ) :
            print ( i , end = " ▁ " ) ;
n = 10 ;
printGenerators ( n ) ;

Iterator variables: i
Python program:
MAX = 100001
perfectDiv = [ 0 ] * MAX
def precomputeCounts ( ) :
    i = 1
    while i * i < MAX :
        for j in range ( i * i , MAX , i * i ) :
            perfectDiv [ j ] += 1
        i += 1
def countPerfectDivisors ( n ) :
    return perfectDiv [ n ]
if __name__ == " _ _ main _ _ " :
    precomputeCounts ( )
    n = 16
    print ( " Total ▁ perfect ▁ divisors ▁ of ▁ " , n , " ▁ = ▁ " , countPerfectDivisors ( n ) )
    n = 12
    print ( " Total ▁ perfect ▁ divisors ▁ of ▁ " , n , " ▁ = ▁ " , countPerfectDivisors ( n ) )

Index/key variables: j, n
Accumulator variables: i
Iterator variables: j
Python program:
import math as mt
MAXN = 100001
spf = [ 0 for i in range ( MAXN ) ]
def sieve ( ) :
    spf [ 1 ] = 1
    for i in range ( 2 , MAXN ) :
        spf [ i ] = i
    for i in range ( 4 , MAXN , 2 ) :
        spf [ i ] = 2
    for i in range ( 3 , mt . ceil ( mt . sqrt ( MAXN ) ) ) :
        if ( spf [ i ] == i ) :
            for j in range ( i * i , MAXN , i ) :
                if ( spf [ j ] == j ) :
                    spf [ j ] = i
def getFactorization ( x ) :
    ret = list ( )
    while ( x != 1 ) :
        ret . append ( spf [ x ] )
        x = x // spf [ x ]
    return ret
sieve ( )
x = 12246
print ( " prime ▁ factorization ▁ for " , x , " : ▁ " , end = " " )
p = getFactorization ( x )
for i in range ( len ( p ) ) :
    print ( p [ i ] , end = " ▁ " )

Index/key variables: i, j, x
Accumulator variables: ret
Iterator variables: i, j
Python program:
def largestGCDSubsequence ( arr , n ) :
    ans = 0
    maxele = max ( arr )
    for i in range ( 2 , maxele + 1 ) :
        count = 0
        for j in range ( n ) :
            if ( arr [ j ] % i == 0 ) :
                count += 1
        ans = max ( ans , count )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 6 , 2 , 5 , 4 ]
    size = len ( arr )
    print ( largestGCDSubsequence ( arr , size ) )

Index/key variables: j
Accumulator variables: count
Iterator variables: i, j
Python program:
MAX = 100006 ;
count = [ 0 ] * MAX ;
def sieve ( ) :
    i = 2 ;
    while ( i * i <= MAX ) :
        if ( count [ i ] == 0 ) :
            for j in range ( 2 * i , MAX , i ) :
                count [ j ] += 1 ;
            count [ i ] = 1 ;
        i += 1 ;
def query ( l , r ) :
    sum = 0 ;
    for i in range ( l , r + 1 ) :
        sum += count [ i ] ;
    return sum ;
sieve ( ) ;
print ( query ( 6 , 10 ) , query ( 1 , 5 ) ) ;

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
def generateNumbers ( factor , n , k ) :
    next = [ 0 ] * k ;
    i = 0 ;
    while ( i < n ) :
        toincrement = 0 ;
        for j in range ( k ) :
            if ( next [ j ] < next [ toincrement ] ) :
                toincrement = j ;
        if ( output != next [ toincrement ] ) :
            output = next [ toincrement ] ;
            print ( next [ toincrement ] , end = " ▁ " ) ;
            i += 1 ;
        next [ toincrement ] += factor [ toincrement ] ;
factor = [ 3 , 5 , 7 ] ;
n = 10 ;
k = len ( factor ) ;
generateNumbers ( factor , n , k ) ;

Index/key variables: j, toincrement
Accumulator variables: i
Iterator variables: j
Python program:
import math
def sumOfRange ( a , b ) :
    i = ( a * ( a + 1 ) ) >> 1 ;
    j = ( b * ( b + 1 ) ) >> 1 ;
    return ( i - j ) ;
def sumofproduct ( n ) :
    sum = 0 ;
    root = int ( math . sqrt ( n ) ) ;
    for i in range ( 1 , root + 1 ) :
        up = int ( n / i ) ;
        low = max ( int ( n / ( i + 1 ) ) , root ) ;
        sum += ( i * sumOfRange ( up , low ) ) ;
        sum += ( i * int ( n / i ) ) ;
    return sum ;
n = 10 ;
print ( sumofproduct ( n ) ) ;

Accumulator variables: sum
Iterator variables: i
Python program:
from math import sqrt
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    if ( n <= 3 ) :
        return True
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return False
    i = 5
    while ( i * i <= n ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return False
        i = i + 6
    return True
def power ( x , y , p ) :
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = ( res * x ) % p
        x = ( x * x ) % p
    return res
def findPrimefactors ( s , n ) :
    while ( n % 2 == 0 ) :
        s . add ( 2 )
        n = n // 2
    for i in range ( 3 , int ( sqrt ( n ) ) , 2 ) :
        while ( n % i == 0 ) :
            s . add ( i )
            n = n // i
    if ( n > 2 ) :
        s . add ( n )
def findPrimitive ( n ) :
    s = set ( )
    if ( isPrime ( n ) == False ) :
        return - 1
    phi = n - 1
    findPrimefactors ( s , phi )
    for r in range ( 2 , phi + 1 ) :
        flag = False
        for it in s :
            if ( power ( r , phi // it , n ) == 1 ) :
                flag = True
                break
        if ( flag == False ) :
            return r
    return - 1
n = 761
print ( " Smallest ▁ primitive ▁ root ▁ of " , n , " is " , findPrimitive ( n ) )

Accumulator variables: s
Iterator variables: i, it, r
Boolean variables: flag
Python program:
def minPower ( n , x ) :
    if ( x == 1 ) :
        return n
    ans = 0
    while ( n > 0 ) :
        ans += ( n % x )
        n //= x
    return ans
n = 5
x = 3
print ( minPower ( n , x ) )

Accumulator variables: ans, n
Python program:
def findKHCF ( x , y , k ) :
    small = min ( x , y )
    count = 1
    for i in range ( 2 , small + 1 ) :
        if ( x % i == 0 and y % i == 0 ) :
            count = count + 1
        if ( count == k ) :
            return i
    return - 1
x = 4
y = 24
k = 3
print ( findKHCF ( x , y , k ) )

Iterator variables: i
Python program:
import math
def findMinNumber ( n ) :
    count = 0
    ans = 1
    while n % 2 == 0 :
        count += 1
        n //= 2
    if count % 2 is not 0 :
        ans *= 2
    for i in range ( 3 , ( int ) ( math . sqrt ( n ) ) + 1 , 2 ) :
        count = 0
        while n % i == 0 :
            count += 1
            n //= i
        if count % 2 is not 0 :
            ans *= i
    if n > 2 :
        ans *= n
    return ans
n = 72
print ( findMinNumber ( n ) )

Accumulator variables: ans, count, n
Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( a == 0 ) :
        return b
    return gcd ( b % a , a )
def findgcd ( n , x , y ) :
    g = gcd ( x , y )
    for i in range ( g ) :
        print ( n )
n = 123
x = 5
y = 2
findgcd ( n , x , y )

Iterator variables: i
Python program:
def gcd ( a , b ) :
    if ( ( a % b ) == 0 ) :
        return b
    return gcd ( b , a % b )
def firstFactorialDivisibleNumber ( x ) :
    i = 1
    new_x = x
    for i in range ( 1 , x ) :
        new_x /= gcd ( i , new_x )
        if ( new_x == 1 ) :
            break
    return i
def countFactorialXNotY ( x , y ) :
    return ( firstFactorialDivisibleNumber ( y ) - firstFactorialDivisibleNumber ( x ) )
x = 15
y = 25
print ( countFactorialXNotY ( x , y ) )

Accumulator variables: new_x
Iterator variables: i
Python program:
def firstFactorialDivisibleNumber ( x ) :
    fact = 1 ;
    for i in range ( 1 , x ) :
        fact = fact * i
        if ( fact % x == 0 ) :
            break
    return i
x = 16
print ( firstFactorialDivisibleNumber ( x ) )

Iterator variables: i
Python program:
def SieveOfEratosthenes ( n , isPrime ) :
    isPrime [ 0 ] = isPrime [ 1 ] = False
    for i in range ( 2 , n + 1 ) :
        isPrime [ i ] = True
    p = 2
    while ( p * p <= n ) :
        if ( isPrime [ p ] == True ) :
            i = p * p
            while ( i <= n ) :
                isPrime [ i ] = False
                i += p
        p += 1
def findPrimePair ( n ) :
    isPrime = [ 0 ] * ( n + 1 )
    SieveOfEratosthenes ( n , isPrime )
    for i in range ( 0 , n ) :
        if ( isPrime [ i ] and isPrime [ n - i ] ) :
            print ( i , ( n - i ) )
            return
n = 74
findPrimePair ( n )

Index/key variables: i, p
Iterator variables: i
Python program:
def getFirstDigit ( x ) :
    while ( x >= 10 ) :
        x //= 10
    return x
def getCountWithSameStartAndEndFrom1 ( x ) :
    if ( x < 10 ) :
        return x
    tens = x // 10
    res = tens + 9
    firstDigit = getFirstDigit ( x )
    lastDigit = x % 10
    if ( lastDigit < firstDigit ) :
        res = res - 1
    return res
def getCountWithSameStartAndEnd ( start , end ) :
    return ( getCountWithSameStartAndEndFrom1 ( end ) - getCountWithSameStartAndEndFrom1 ( start - 1 ) )
start = 5
end = 40
print ( getCountWithSameStartAndEnd ( start , end ) )

Accumulator variables: x
Python program:
def sieveOfEratosthenes ( n , isPrime ) :
    isPrime [ 0 ] = isPrime [ 1 ] = False
    for i in range ( 2 , n + 1 ) :
        isPrime [ i ] = True
    p = 2
    while ( p * p <= n ) :
        if ( isPrime [ p ] == True ) :
            i = p * 2
            while ( i <= n ) :
                isPrime [ i ] = False
                i = i + p
        p = p + 1
def rightTruPrime ( n ) :
    isPrime = [ None ] * ( n + 1 )
    sieveOfEratosthenes ( n , isPrime )
    while ( n != 0 ) :
        if ( isPrime [ n ] ) :
            n = n // 10
        else :
            return False
    return True
n = 59399
if ( rightTruPrime ( n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, n, p
Iterator variables: i
Python program:
def SieveOfEratosthenes ( n , prime ) :
    for i in range ( 0 , n + 1 ) :
        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
def mersennePrimes ( n ) :
    prime = [ 0 ] * ( n + 1 )
    SieveOfEratosthenes ( n , prime )
    k = 2
    while ( ( ( 1 << k ) - 1 ) <= n ) :
        num = ( 1 << k ) - 1
        if ( prime [ num ] ) :
            print ( num , end = " ▁ " )
        k += 1
n = 31
print ( " Mersenne ▁ prime ▁ numbers ▁ smaller " , " than ▁ or ▁ equal ▁ to ▁ " , n )
mersennePrimes ( n )

Index/key variables: i, num, p
Accumulator variables: k
Iterator variables: i
Python program:
def findSum ( N , K ) :
    ans = 0 ;
    for i in range ( 1 , N + 1 ) :
        ans += ( i % K ) ;
    return ans ;
N = 10 ;
K = 2 ;
print ( findSum ( N , K ) ) ;

Accumulator variables: ans
Iterator variables: i
Python program:
def divisible ( N , digit ) :
    ans = 0 ;
    for i in range ( len ( N ) ) :
        ans = ( ans * 10 + ( ord ( N [ i ] ) - ord ( '0' ) ) ) ;
        ans %= digit ;
    return ( ans == 0 ) ;
def allDigits ( N ) :
    divide = [ False ] * 10 ;
    for digit in range ( 2 , 10 ) :
        if ( divisible ( N , digit ) ) :
            divide [ digit ] = True ;
    result = 0 ;
    for i in range ( len ( N ) ) :
        if ( divide [ ( ord ( N [ i ] ) - ord ( '0' ) ) ] == True ) :
            result += 1 ;
    return result ;
N = "122324" ;
print ( allDigits ( N ) ) ;

Index/key variables: digit, i
Accumulator variables: ans, result
Iterator variables: digit, i
Python program:
from math import sqrt
def getSum ( n ) :
    for i in range ( 1 , int ( sqrt ( n ) ) + 1 ) :
        if n % i == 0 :
            if n // i == i :
                summ += i
            else :
                summ += i
                summ += n // i
    return summ - n
def printAliquot ( n ) :
    print ( n , end = " ▁ " )
    s = set ( )
    s . add ( n )
    nextt = 0
    while n > 0 :
        n = getSum ( n )
        if n in s :
            print ( " Repeats ▁ with " , n )
            break
        print ( n , end = " ▁ " )
        s . add ( n )
if __name__ == " _ _ main _ _ " :
    printAliquot ( 12 )

Accumulator variables: s, summ
Iterator variables: i
Python program:
def countNums ( n , x , y ) :
    arr = [ False for i in range ( n + 2 ) ]
    if ( x <= n ) :
        arr [ x ] = True
    if ( y <= n ) :
        arr [ y ] = True
    result = 0
    for i in range ( min ( x , y ) , n + 1 ) :
        if ( arr [ i ] ) :
            if ( i + x <= n ) :
                arr [ i + x ] = True
            if ( i + y <= n ) :
                arr [ i + y ] = True
            result = result + 1
    return result
n = 15
x = 5
y = 7
print ( countNums ( n , x , y ) )

Index/key variables: i, x, y
Iterator variables: i
Python program:
def reverse ( x ) :
    rev = 0 ;
    while ( x > 0 ) :
        rev = ( rev * 10 ) + x % 10 ;
        x = int ( x / 10 ) ;
    return rev ;
def printEmirp ( n ) :
    prime = [ 1 ] * ( n + 1 ) ;
    p = 2 ;
    while ( p * p <= n ) :
        if ( prime [ p ] == 1 ) :
            for i in range ( p * 2 , n + 1 , p ) :
                prime [ i ] = 0 ;
        p += 1 ;
    for p in range ( 2 , n + 1 ) :
        if ( prime [ p ] == 1 ) :
            rev = reverse ( p ) ;
            if ( p != rev and rev <= n and prime [ rev ] == 1 ) :
                print ( p , rev , end = " ▁ " ) ;
                prime [ rev ] = 0 ;
n = 100 ;
printEmirp ( n ) ;

Index/key variables: i, p, rev
Iterator variables: i, p
Python program:
import math
def isPowerful ( n ) :
    while ( n % 2 == 0 ) :
        power = 0
        while ( n % 2 == 0 ) :
            n = n // 2
            power = power + 1
        if ( power == 1 ) :
            return False
    for factor in range ( 3 , int ( math . sqrt ( n ) ) + 1 , 2 ) :
        power = 0
        while ( n % factor == 0 ) :
            n = n // factor
            power = power + 1
        if ( power == 1 ) :
            return false
    return ( n == 1 )
print ( " YES " if isPowerful ( 20 ) else " NO " )
print ( " YES " if isPowerful ( 27 ) else " NO " )

Iterator variables: factor
Python program:
def checkHarshad ( n ) :
    st = str ( n )
    sum = 0
    length = len ( st )
    for i in st :
        sum = sum + int ( i )
    if ( n % sum == 0 ) :
        return " Yes "
    else :
        return " No "
number = 18
print ( checkHarshad ( number ) )

Iterator variables: i
Python program:
def isKeith ( x ) :
    terms = [ ] ;
    temp = x ;
    while ( temp > 0 ) :
        terms . append ( temp % 10 ) ;
        temp = int ( temp / 10 ) ;
        n += 1 ;
    terms . reverse ( ) ;
    next_term = 0 ;
    i = n ;
    while ( next_term < x ) :
        next_term = 0 ;
        for j in range ( 1 , n + 1 ) :
            next_term += terms [ i - j ] ;
        terms . append ( next_term ) ;
        i += 1 ;
    return ( next_term == x ) ;
print ( " Yes " ) if ( isKeith ( 14 ) ) else print ( " No " ) ;
print ( " Yes " ) if ( isKeith ( 12 ) ) else print ( " No " ) ;
print ( " Yes " ) if ( isKeith ( 197 ) ) else print ( " No " ) ;

Accumulator variables: i, n, next_term, terms
Iterator variables: j
Python program:
import math
def isPerfect ( n ) :
    s = math . sqrt ( n )
    return ( s * s == n )
def divisorsCount ( n ) :
    count = 0
    for i in range ( 1 , ( int ) ( math . sqrt ( n ) + 2 ) ) :
        if ( n % i == 0 ) :
            if ( n // i == i ) :
                count = count + 1
            else :
                count = count + 2
    return count
def kDivisors ( a , b , k ) :
    for i in range ( a , b + 1 ) :
        if ( isPerfect ( i ) ) :
            if ( divisorsCount ( i ) == k ) :
                count = count + 1
    return count
a = 2
b = 49
k = 3
print ( kDivisors ( a , b , k ) )

Iterator variables: i
Python program:
MAX = 3000 ;
def smartNumber ( n ) :
    primes = [ 0 ] * MAX ;
    result = [ ] ;
    for i in range ( 2 , MAX ) :
        if ( primes [ i ] == 0 ) :
            primes [ i ] = 1 ;
            j = i * 2 ;
            while ( j < MAX ) :
                primes [ j ] -= 1 ;
                if ( ( primes [ j ] + 3 ) == 0 ) :
                    result . append ( j ) ;
                j = j + i ;
    result . sort ( ) ;
    return result [ n - 1 ] ;
n = 50 ;
print ( smartNumber ( n ) ) ;

Index/key variables: i, j
Accumulator variables: result
Iterator variables: i