dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def countEqualElementPairs ( arr , N ) :
    mp = { }
    for i in range ( N ) :
        if arr [ i ] in mp :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
    total = 0
    for key , value in mp . items ( ) :
        total += ( value * ( value - 1 ) ) / 2
    for i in range ( N ) :
        print ( int ( total - ( mp [ arr [ i ] ] - 1 ) ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 1 , 2 ]
    N = len ( arr )
    countEqualElementPairs ( arr , N )

Index/key variables: i
Accumulator variables: total
Iterator variables: i, key, value
Python program:
def count ( N ) :
    sum = 0 ;
    for i in range ( N + 1 ) :
        sum += 7 * ( 8 ** ( i - 1 ) ) ;
    return int ( sum ) ;
if __name__ == " _ _ main _ _ " :
    N = 4 ;
    print ( count ( N ) ) ;

Accumulator variables: sum
Iterator variables: i
Python program:
from math import sqrt ;
def isPalindrome ( n ) :
    string = str ( n ) ;
    s = 0 ; e = len ( string ) - 1 ;
    while ( s < e ) :
        if ( string [ s ] != string [ e ] ) :
            return False ;
        s += 1 ;
        e -= 1 ;
    return True ;
def palindromicDivisors ( n ) :
    PalindromDivisors = [ ] ;
    for i in range ( 1 , int ( sqrt ( n ) ) ) :
        if ( n % i == 0 ) :
            if ( n // i == i ) :
                if ( isPalindrome ( i ) ) :
                    PalindromDivisors . append ( i ) ;
            else :
                if ( isPalindrome ( i ) ) :
                    PalindromDivisors . append ( i ) ;
                if ( isPalindrome ( n // i ) ) :
                    PalindromDivisors . append ( n // i ) ;
    PalindromDivisors . sort ( ) ;
    for i in range ( len ( PalindromDivisors ) ) :
        print ( PalindromDivisors [ i ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    n = 66 ;
    palindromicDivisors ( n ) ;

Index/key variables: e, i, s
Accumulator variables: PalindromDivisors
Iterator variables: i
Python program:
import sys
def findMinDel ( arr , n ) :
    min_num = sys . maxsize ;
    for i in range ( n ) :
        min_num = min ( arr [ i ] , min_num ) ;
    cnt = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] == min_num ) :
            cnt += 1 ;
    return n - cnt ;
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 3 , 2 ] ;
    n = len ( arr ) ;
    print ( findMinDel ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def print_primes_till_N ( N ) :
    i , j , flag = 0 , 0 , 0 ;
    print ( " Prime ▁ numbers ▁ between ▁ 1 ▁ and ▁ " , N , " ▁ are : " ) ;
    for i in range ( 1 , N + 1 , 1 ) :
        if ( i == 1 or i == 0 ) :
            continue ;
        flag = 1 ;
        for j in range ( 2 , ( ( i // 2 ) + 1 ) , 1 ) :
            if ( i % j == 0 ) :
                flag = 0 ;
                break ;
        if ( flag == 1 ) :
            print ( i , end = " ▁ " ) ;
N = 100 ;
print_primes_till_N ( N ) ;

Iterator variables: i, j
Python program:
MAX = 32
def findX ( A , B ) :
    X = 0 ;
    for bit in range ( MAX ) :
        tempBit = 1 << bit ;
        bitOfX = A & B & tempBit ;
        X += bitOfX ;
    return X ;
if __name__ == " _ _ main _ _ " :
    A = 11 ; B = 13 ;
    print ( findX ( A , B ) ) ;

Accumulator variables: X
Iterator variables: bit
Python program:
def cntSubSets ( arr , n ) :
    maxVal = max ( arr ) ;
    cnt = 0 ;
    for i in range ( n ) :
        if ( arr [ i ] == maxVal ) :
            cnt += 1 ;
    return ( ( 2 ** cnt ) - 1 ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 1 , 2 ] ;
    n = len ( arr ) ;
    print ( cntSubSets ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
import sys
def findProb ( arr , n ) :
    maxSum = - ( sys . maxsize - 1 ) ;
    maxCount = 0 ;
    totalPairs = 0 ;
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            sum = arr [ i ] + arr [ j ] ;
            if ( sum == maxSum ) :
                maxCount += 1 ;
            elif ( sum > maxSum ) :
                maxSum = sum ;
                maxCount = 1 ;
            totalPairs += 1 ;
    prob = maxCount / totalPairs ;
    return prob ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 1 , 2 , 2 , 2 ] ;
    n = len ( arr ) ;
    print ( findProb ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: maxCount, totalPairs
Iterator variables: i, j
Python program:
import math
def maxCommonFactors ( a , b ) :
    gcd = math . gcd ( a , b )
    ans = 1 ;
    i = 2
    while ( i * i <= gcd ) :
        if ( gcd % i == 0 ) :
            ans += 1
            while ( gcd % i == 0 ) :
                gcd = gcd // i
        i += 1
    if ( gcd != 1 ) :
        ans += 1
    return ans
a = 12
b = 18
print ( maxCommonFactors ( a , b ) )

Accumulator variables: ans, i
Python program:
days = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ;
def dayOfYear ( date ) :
    year = ( int ) ( date [ 0 : 4 ] ) ;
    month = ( int ) ( date [ 5 : 7 ] ) ;
    day = ( int ) ( date [ 8 : ] ) ;
    if ( month > 2 and year % 4 == 0 and ( year % 100 != 0 or year % 400 == 0 ) ) :
        day += 1 ;
    month -= 1 ;
    while ( month > 0 ) :
        day = day + days [ month - 1 ] ;
        month -= 1 ;
    return day ;
if __name__ == ' _ _ main _ _ ' :
    date = "2019-01-09" ;
    print ( dayOfYear ( date ) ) ;

Accumulator variables: month
Python program:
def Cells ( n , x ) :
    ans = 0 ;
    for i in range ( 1 , n + 1 ) :
        if ( x % i == 0 and x / i <= n ) :
            ans += 1 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    n = 6 ; x = 12 ;
    print ( Cells ( n , x ) ) ;

Accumulator variables: ans
Iterator variables: i
Python program:
def minOperations ( x , y , p , q ) :
    if ( y % x != 0 ) :
        return - 1
    d = y // x
    a = 0
    while ( d % p == 0 ) :
        d //= p
        a += 1
    b = 0
    while ( d % q == 0 ) :
        d //= q
        b += 1
    if ( d != 1 ) :
        return - 1
    return ( a + b )
x = 12
y = 2592
p = 2
q = 3
print ( minOperations ( x , y , p , q ) )

Accumulator variables: a, b, d
Python program:
from math import sqrt
def nCr ( n ) :
    if ( n < 4 ) :
        return 0 ;
    answer = n * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) ;
    answer //= 24 ;
    return answer ;
def countQuadruples ( N , K ) :
    M = N // K ;
    answer = nCr ( M ) ;
    for i in range ( 2 , M ) :
        j = i ;
        temp2 = M // i ;
        count = 0 ;
        check = 0 ;
        temp = j ;
        while ( j % 2 == 0 ) :
            count += 1 ;
            j //= 2 ;
            if ( count >= 2 ) :
                break ;
        if ( count >= 2 ) :
            check = 1 ;
        for k in range ( 3 , int ( sqrt ( temp ) ) , 2 ) :
            cnt = 0 ;
            while ( j % k == 0 ) :
                cnt += 1 ;
                j //= k ;
                if ( cnt >= 2 ) :
                    break ;
            if ( cnt >= 2 ) :
                check = 1 ;
                break ;
            elif ( cnt == 1 ) :
                count += 1 ;
        if ( j > 2 ) :
            count += 1 ;
        if ( check ) :
            continue ;
        else :
            if ( count % 2 == 1 ) :
                answer -= nCr ( temp2 ) ;
            else :
                answer += nCr ( temp2 ) ;
    return answer ;
if __name__ == " _ _ main _ _ " :
    N = 10 ; K = 2 ;
    print ( countQuadruples ( N , K ) ) ;

Accumulator variables: answer, cnt, count, j
Iterator variables: i, k
Python program:
def isVowel ( ch ) :
    if ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) :
        return True
    else :
        return False
def fact ( n ) :
    if ( n < 2 ) :
        return 1
    return n * fact ( n - 1 )
def only_vowels ( freq ) :
    denom = 1
    cnt_vwl = 0
    for itr in freq :
        if ( isVowel ( itr ) ) :
            denom *= fact ( freq [ itr ] )
            cnt_vwl += freq [ itr ]
    return fact ( cnt_vwl ) // denom
def all_vowels_together ( freq ) :
    vow = only_vowels ( freq )
    denom = 1
    cnt_cnst = 0
    for itr in freq :
        if ( isVowel ( itr ) == False ) :
            denom *= fact ( freq [ itr ] )
            cnt_cnst += freq [ itr ]
    ans = fact ( cnt_cnst + 1 ) // denom
    return ( ans * vow )
def total_permutations ( freq ) :
    cnt = 0
    denom = 1
    for itr in freq :
        denom *= fact ( freq [ itr ] )
        cnt += freq [ itr ]
    return fact ( cnt ) // denom
def no_vowels_together ( word ) :
    freq = dict ( )
    for i in word :
        ch = i . lower ( )
        freq [ ch ] = freq . get ( ch , 0 ) + 1
    total = total_permutations ( freq )
    vwl_tgthr = all_vowels_together ( freq )
    res = total - vwl_tgthr
    return res
word = " allahabad "
ans = no_vowels_together ( word )
print ( ans )
word = " geeksforgeeks "
ans = no_vowels_together ( word )
print ( ans )
word = " abcd "
ans = no_vowels_together ( word )
print ( ans )

Index/key variables: ch, itr
Accumulator variables: cnt, cnt_cnst, cnt_vwl, denom
Iterator variables: i, itr
Python program:
def addToArrayForm ( A , K ) :
    v , ans = [ ] , [ ]
    rem , i = 0 , 0
    for i in range ( len ( A ) - 1 , - 1 , - 1 ) :
        my = A [ i ] + ( K % 10 ) + rem
        if my > 9 :
            rem = 1
            v . append ( my % 10 )
        else :
            v . append ( my )
            rem = 0
        K = K // 10
    while K > 0 :
        my = ( K % 10 ) + rem
        v . append ( my % 10 )
        if my // 10 > 0 :
            rem = 1
        else :
            rem = 0
        K = K // 10
    if rem > 0 :
        v . append ( rem )
    for i in range ( len ( v ) - 1 , - 1 , - 1 ) :
        ans . append ( v [ i ] )
    return ans
if __name__ == " _ _ main _ _ " :
    A = [ 2 , 7 , 4 ]
    K = 181
    ans = addToArrayForm ( A , K )
    for i in range ( 0 , len ( ans ) ) :
        print ( ans [ i ] , end = " " )

Index/key variables: i
Accumulator variables: ans, v
Iterator variables: i
Python program:
MAX = 100005 ;
def kadaneAlgorithm ( ar , n ) :
    sum = 0 ; maxSum = 0 ;
    for i in range ( n ) :
        sum += ar [ i ] ;
        if ( sum < 0 ) :
            sum = 0 ;
        maxSum = max ( maxSum , sum ) ;
    return maxSum ;
def maxFunction ( arr , n ) :
    b = [ 0 ] * MAX ;
    c = [ 0 ] * MAX ;
    for i in range ( n - 1 ) :
        if ( i & 1 ) :
            b [ i ] = abs ( arr [ i + 1 ] - arr [ i ] ) ;
            c [ i ] = - b [ i ] ;
        else :
            c [ i ] = abs ( arr [ i + 1 ] - arr [ i ] ) ;
            b [ i ] = - c [ i ] ;
    ans = kadaneAlgorithm ( b , n - 1 ) ;
    ans = max ( ans , kadaneAlgorithm ( c , n - 1 ) ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 5 , 4 , 7 ] ;
    n = len ( arr )
    print ( maxFunction ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def isPalindrome ( n ) :
    divisor = 1
    while ( int ( n / divisor ) >= 10 ) :
        divisor *= 10
    while ( n != 0 ) :
        leading = int ( n / divisor )
        trailing = n % 10
        if ( leading != trailing ) :
            return False
        n = int ( ( n % divisor ) / 10 )
        divisor = int ( divisor / 100 )
    return True
def largestPalindrome ( A , n ) :
    currentMax = - 1
    for i in range ( 0 , n , 1 ) :
        if ( A [ i ] > currentMax and isPalindrome ( A [ i ] ) ) :
            currentMax = A [ i ]
    return currentMax
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 232 , 54545 , 999991 ]
    n = len ( A )
    print ( largestPalindrome ( A , n ) )

Index/key variables: i
Accumulator variables: divisor
Iterator variables: i
Python program:
def getFinalElement ( n ) :
    finalNum = 2
    while finalNum * 2 <= n :
        finalNum *= 2
    return finalNum
if __name__ == " _ _ main _ _ " :
    N = 12
    print ( getFinalElement ( N ) )

Accumulator variables: finalNum
Python program:
import math as mt
def SieveOfEratosthenes ( prime , p_size ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , mt . ceil ( mt . sqrt ( p_size + 1 ) ) ) :
        if ( prime [ p ] ) :
            for i in range ( p * 2 , p_size + 1 , p ) :
                prime [ i ] = False
def SumOfElements ( arr , n ) :
    prime = [ True for i in range ( n + 1 ) ]
    SieveOfEratosthenes ( prime , n + 1 )
    i , j = 0 , 0
    m = dict ( )
    for i in range ( n ) :
        if arr [ i ] in m . keys ( ) :
            m [ arr [ i ] ] += 1
        else :
            m [ arr [ i ] ] = 1
    Sum = 0
    for i in m :
        if ( prime [ m [ i ] ] ) :
            Sum += ( i )
    return Sum
arr = [ 5 , 4 , 6 , 5 , 4 , 6 ]
n = len ( arr )
print ( SumOfElements ( arr , n ) )

Index/key variables: i, p
Accumulator variables: Sum
Iterator variables: i, p
Python program:
def isPalindrome ( num ) :
    reverse_num = 0
    temp = num
    while ( temp != 0 ) :
        remainder = temp % 10
        reverse_num = reverse_num * 10 + remainder
        temp = int ( temp / 10 )
    if ( reverse_num == num ) :
        return True
    return False
def isOddLength ( num ) :
    count = 0
    while ( num > 0 ) :
        num = int ( num / 10 )
        count += 1
    if ( count % 2 != 0 ) :
        return True
    return False
def sumOfAllPalindrome ( L , R ) :
    sum = 0
    if ( L <= R ) :
        for i in range ( L , R + 1 , 1 ) :
            if ( isPalindrome ( i ) and isOddLength ( i ) ) :
                sum += i
    return sum
if __name__ == ' _ _ main _ _ ' :
    L = 110
    R = 1130
    print ( sumOfAllPalindrome ( L , R ) )

Accumulator variables: count, sum
Iterator variables: i
Python program:
def fact ( n ) :
    f = 1
    for i in range ( 2 , n + 1 ) :
        f = f * i
    return f
def waysOfConsonants ( size1 , freq ) :
    ans = fact ( size1 )
    for i in range ( 26 ) :
        if ( i == 0 or i == 4 or i == 8 or i == 14 or i == 20 ) :
            continue
        else :
            ans = ans // fact ( freq [ i ] )
    return ans
def waysOfVowels ( size2 , freq ) :
    return ( fact ( size2 ) // ( fact ( freq [ 0 ] ) * fact ( freq [ 4 ] ) * fact ( freq [ 8 ] ) * fact ( freq [ 14 ] ) * fact ( freq [ 20 ] ) ) )
def countWays ( str1 ) :
    freq = [ 0 ] * 26
    for i in range ( len ( str1 ) ) :
        freq [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1
    vowel = 0
    consonant = 0
    for i in range ( len ( str1 ) ) :
        if ( str1 [ i ] != ' a ' and str1 [ i ] != ' e ' and str1 [ i ] != ' i ' and str1 [ i ] != ' o ' and str1 [ i ] != ' u ' ) :
            consonant += 1
        else :
            vowel += 1
    return ( waysOfConsonants ( consonant + 1 , freq ) * waysOfVowels ( vowel , freq ) )
if __name__ == " _ _ main _ _ " :
    str1 = " geeksforgeeks "
    print ( countWays ( str1 ) )

Index/key variables: i
Accumulator variables: consonant, vowel
Iterator variables: i
Python program:
def calculateAlternateSum ( n ) :
    if ( n <= 0 ) :
        return 0
    fibo = [ 0 ] * ( n + 1 )
    fibo [ 0 ] = 0
    fibo [ 1 ] = 1
    sum = pow ( fibo [ 0 ] , 2 ) + pow ( fibo [ 1 ] , 2 )
    for i in range ( 2 , n + 1 ) :
        fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]
        if ( i % 2 == 0 ) :
            sum -= fibo [ i ]
        else :
            sum += fibo [ i ]
    return sum
if __name__ == " _ _ main _ _ " :
    n = 8
    print ( " Alternating ▁ Fibonacci ▁ Sum ▁ upto ▁ " , n , " ▁ terms : ▁ " , calculateAlternateSum ( n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
import math
def countDigits ( val , arr ) :
    while ( val > 0 ) :
        digit = val % 10
        arr [ int ( digit ) ] += 1
        val = val // 10
    return ;
def countFrequency ( x , n ) :
    freq_count = [ 0 ] * 10
    for i in range ( 1 , n + 1 ) :
        val = math . pow ( x , i )
        countDigits ( val , freq_count )
    for i in range ( 10 ) :
        print ( freq_count [ i ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    x = 15
    n = 3
    countFrequency ( x , n )

Index/key variables: i
Iterator variables: i
Python program:
def countSolutions ( a ) :
    count = 0
    for i in range ( a + 1 ) :
        if ( a == ( i + ( a ^ i ) ) ) :
            count += 1
    return count
if __name__ == " _ _ main _ _ " :
    a = 3
    print ( countSolutions ( a ) )

Accumulator variables: count
Iterator variables: i
Python program:
def calculateAreaSum ( l , b ) :
    size = 1
    maxSize = min ( l , b )
    totalArea = 0
    for i in range ( 1 , maxSize + 1 ) :
        totalSquares = ( ( l - size + 1 ) * ( b - size + 1 ) )
        area = ( totalSquares * size * size )
        totalArea += area
        size += 1
    return totalArea
if __name__ == " _ _ main _ _ " :
    l = 4
    b = 3
    print ( calculateAreaSum ( l , b ) )

Accumulator variables: size, totalArea
Iterator variables: i
Python program:
def boost_hyperfactorial ( num ) :
    val = 1 ;
    for i in range ( 1 , num + 1 ) :
        val = val * pow ( i , i ) ;
    return val ;
num = 5 ;
print ( boost_hyperfactorial ( num ) ) ;

Iterator variables: i
Python program:
def boost_hyperfactorial ( num ) :
    val = 1 ;
    for i in range ( 1 , num + 1 ) :
        for j in range ( 1 , i + 1 ) :
            val *= i ;
    return val ;
num = 5 ;
print ( boost_hyperfactorial ( num ) ) ;

Accumulator variables: val
Iterator variables: i, j
Python program:
rows = 3 ;
cols = 3 ;
def meanVector ( mat ) :
    print ( " [ ▁ " , end = " " ) ;
    for i in range ( rows ) :
        mean = 0.00 ;
        sum = 0 ;
        for j in range ( cols ) :
            sum = sum + mat [ j ] [ i ] ; mean = int ( sum / rows ) ; print ( mean , end = " ▁ " ) ; print ( " ] " ) ;
mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ;
meanVector ( mat ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
import math
def primeFactors ( n ) :
    res = [ ]
    if ( n % 2 == 0 ) :
        while ( n % 2 == 0 ) :
            n = int ( n / 2 )
        res . append ( 2 )
    for i in range ( 3 , int ( math . sqrt ( n ) ) , 2 ) :
        if ( n % i == 0 ) :
            while ( n % i == 0 ) :
                n = int ( n / i )
            res . append ( i )
    if ( n > 2 ) :
        res . append ( n )
    return res
def isHoax ( n ) :
    pf = primeFactors ( n )
    if ( pf [ 0 ] == n ) :
        return False
    all_pf_sum = 0
    for i in range ( 0 , len ( pf ) ) :
        pf_sum = 0
        while ( pf [ i ] > 0 ) :
            pf_sum += pf [ i ] % 10
            pf [ i ] = int ( pf [ i ] / 10 )
        all_pf_sum += pf_sum
    sum_n = 0 ;
    while ( n > 0 ) :
        sum_n += n % 10
        n = int ( n / 10 )
    return sum_n == all_pf_sum
n = 84 ;
if ( isHoax ( n ) ) :
    print ( " A Hoax Number " )
else :
    print ( " Not a Hoax Number " )

Index/key variables: i
Accumulator variables: all_pf_sum, pf_sum, res, sum_n
Iterator variables: i
Python program:
def LucasLehmer ( n ) :
    current_val = 4 ;
    series = [ ]
    series . append ( current_val )
    for i in range ( n ) :
        current_val = current_val * current_val - 2 ;
        series . append ( current_val ) ;
    for i in range ( n + 1 ) :
        print ( " Term " , i , " : " , series [ i ] )
if __name__ == ' _ _ main _ _ ' :
    n = 5 ;
    LucasLehmer ( n ) ;

Index/key variables: i
Accumulator variables: series
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
def largestPalindrome ( A , n ) :
    A . sort ( )
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( isPalindrome ( A [ i ] ) ) :
            return A [ i ]
    return - 1
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 232 , 54545 , 999991 ]
    n = len ( A )
    print ( largestPalindrome ( A , n ) )

Index/key variables: i
Accumulator variables: divisor
Iterator variables: i
Python program:
def findSum ( n , a , b ) :
    sum = 0
    for i in range ( 0 , n , 1 ) :
        if ( i % a == 0 or i % b == 0 ) :
            sum += i
    return sum
if __name__ == ' _ _ main _ _ ' :
    n = 10
    a = 3
    b = 5
    print ( findSum ( n , a , b ) )

Accumulator variables: sum
Iterator variables: i
Python program:
def LCM ( arr , n ) :
    max_num = 0 ;
    for i in range ( n ) :
        if ( max_num < arr [ i ] ) :
            max_num = arr [ i ] ;
    res = 1 ;
    while ( x <= max_num ) :
        indexes = [ ] ;
        for j in range ( n ) :
            if ( arr [ j ] % x == 0 ) :
                indexes . append ( j ) ;
        if ( len ( indexes ) >= 2 ) :
            for j in range ( len ( indexes ) ) :
                arr [ indexes [ j ] ] = int ( arr [ indexes [ j ] ] / x ) ;
            res = res * x ;
        else :
            x += 1 ;
    for i in range ( n ) :
        res = res * arr [ i ] ;
    return res ;
arr = [ 1 , 2 , 3 , 4 , 5 , 10 , 20 , 35 ] ;
n = len ( arr ) ;
print ( LCM ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: indexes, x
Iterator variables: i, j
Python program:
import math
MAX = 10000 ;
primes = [ ] ;
def sieveSundaram ( ) :
    marked = [ False ] * ( int ( MAX / 2 ) + 100 ) ;
    for i in range ( 1 , int ( ( math . sqrt ( MAX ) - 1 ) / 2 ) + 1 ) :
        for j in range ( ( i * ( i + 1 ) ) << 1 , int ( MAX / 2 ) + 1 , 2 * i + 1 ) :
            marked [ j ] = True ;
    primes . append ( 2 ) ;
    for i in range ( 1 , int ( MAX / 2 ) + 1 ) :
        if ( marked [ i ] == False ) :
            primes . append ( 2 * i + 1 ) ;
def findPrimes ( n ) :
    if ( n <= 2 or n % 2 != 0 ) :
        print ( " Invalid ▁ Input " ) ;
        return ;
    i = 0 ;
    while ( primes [ i ] <= n // 2 ) :
        diff = n - primes [ i ] ;
        if diff in primes :
            print ( primes [ i ] , " + " , diff , " = " , n ) ;
            return ;
        i += 1 ;
sieveSundaram ( ) ;
findPrimes ( 4 ) ;
findPrimes ( 38 ) ;
findPrimes ( 100 ) ;

Index/key variables: i, j
Accumulator variables: primes
Iterator variables: i, j
Python program:
MAX = 10001
def sieveOfEratosthenes ( s ) :
    prime = [ False for i in range ( MAX + 1 ) ]
    for i in range ( 2 , MAX + 1 , 2 ) :
        s [ i ] = 2 ;
    for i in range ( 3 , MAX , 2 ) :
        if ( prime [ i ] == False ) :
            s [ i ] = i
            for j in range ( i , MAX + 1 , 2 ) :
                if j * j > MAX :
                    break
                if ( prime [ i * j ] == False ) :
                    prime [ i * j ] = True
                    s [ i * j ] = i
def kPrimeFactor ( n , k , s ) :
    while ( n > 1 ) :
        if ( k == 1 ) :
            return s [ n ]
        k -= 1
        n //= s [ n ]
    return - 1
s = [ - 1 for i in range ( MAX + 1 ) ]
sieveOfEratosthenes ( s )
n = 12
k = 3
print ( kPrimeFactor ( n , k , s ) )
n = 14
k = 3
print ( kPrimeFactor ( n , k , s ) )

Index/key variables: i, n
Accumulator variables: k
Iterator variables: i, j
Python program:
import math as mt
def sumDivisorsOfDivisors ( n ) :
    mp = dict ( )
    for j in range ( 2 , mt . ceil ( mt . sqrt ( n ) ) ) :
        count = 0
        while ( n % j == 0 ) :
            n //= j
            count += 1
        if ( count ) :
            mp [ j ] = count
    if ( n != 1 ) :
        mp [ n ] = 1
    ans = 1
    for it in mp :
        pw = 1
        summ = 0
        for i in range ( mp [ it ] + 1 , 0 , - 1 ) :
            summ += ( i * pw )
            pw *= it
        ans *= summ
    return ans
n = 10
print ( sumDivisorsOfDivisors ( n ) )

Index/key variables: it, j, n
Accumulator variables: ans, count, pw, summ
Iterator variables: i, it, j
Python program:
def fractionToDecimal ( numr , denr ) :
    res = " "
    mp = { }
    rem = numr % denr
    while ( ( rem != 0 ) and ( rem not in mp ) ) :
        mp [ rem ] = len ( res )
        rem = rem * 10
        res_part = rem // denr
        res += str ( res_part )
        rem = rem % denr
    if ( rem == 0 ) :
        return " "
    else :
        return res [ mp [ rem ] : ]
numr , denr = 50 , 22
res = fractionToDecimal ( numr , denr )
if ( res == " " ) :
    print ( " No ▁ recurring ▁ sequence " )
else :
    print ( " Recurring ▁ sequence ▁ is " , res )

Index/key variables: rem
Accumulator variables: res