dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import math
MAX = 16
nCr = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]
def binomial ( ) :
    for i in range ( MAX ) :
        for j in range ( 0 , i + 1 ) :
            if j == 0 or j == i :
                nCr [ i ] [ j ] = 1
            else :
                nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ]
def findTanNTheta ( tanTheta , n ) :
    numerator = 0
    denominator = 1
    ans = 0
    toggle = 1
    for i in range ( 1 , n + 1 , 2 ) :
        numerator = ( numerator + nCr [ n ] [ i ] * ( tanTheta ** ( i ) ) * toggle )
        toggle = toggle * - 1
    toggle = - 1
    for i in range ( 2 , n + 1 , 2 ) :
        numerator = ( numerator + nCr [ n ] [ i ] * ( tanTheta ** i ) * toggle )
        toggle = toggle * - 1
    ans = numerator / denominator
    return ans
if __name__ == ' _ _ main _ _ ' :
    binomial ( )
    tanTheta = 0.3
    n = 10
    print ( findTanNTheta ( tanTheta , n ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
def printCombination ( n ) :
    for i in range ( 1 , n ) :
        if ( i % 3 != 0 ) :
            for j in range ( 1 , n ) :
                if ( j % 3 != 0 ) :
                    for k in range ( 1 , n ) :
                        if ( k % 3 != 0 and ( i + j + k ) == n ) :
                            print ( i , j , k ) ;
                            return ;
n = 233 ;
printCombination ( n ) ;

Iterator variables: i, j, k
Python program:
MAXN = 100005
spf = [ 0 ] * MAXN
sum_digits = [ 0 ] * MAXN
isValid = [ 0 ] * MAXN
ans = [ 0 ] * MAXN
def Smallest_prime_factor ( ) :
    for i in range ( 1 , MAXN ) :
        spf [ i ] = i
    for i in range ( 4 , MAXN , 2 ) :
        spf [ i ] = 2
    i = 3
    while i * i <= MAXN :
        if ( spf [ i ] == i ) :
            for j in range ( i * i , MAXN , i ) :
                if ( spf [ j ] == j ) :
                    spf [ j ] = i
        i += 2
def Digit_Sum ( copy ) :
    d = 0
    while ( copy ) :
        d += copy % 10
        copy //= 10
    return d
def Sum_Of_All_Digits ( ) :
    for n in range ( 2 , MAXN ) :
        sum_digits [ n ] = ( sum_digits [ n // spf [ n ] ] + Digit_Sum ( spf [ n ] ) )
        if ( Digit_Sum ( n ) == sum_digits [ n ] ) :
            isValid [ n ] = True
    for n in range ( 2 , MAXN ) :
        if ( isValid [ n ] ) :
            ans [ n ] = 1
        ans [ n ] += ans [ n - 1 ]
if __name__ == " _ _ main _ _ " :
    Smallest_prime_factor ( )
    Sum_Of_All_Digits ( )
    l = 2
    r = 3
    print ( " Valid ▁ numbers ▁ in ▁ the ▁ range " , l , r , " are " , ans [ r ] - ans [ l - 1 ] )
    l = 2
    r = 10
    print ( " Valid ▁ numbers ▁ in ▁ the ▁ range " , l , r , " are " , ans [ r ] - ans [ l - 1 ] )

Index/key variables: i, j, n, r
Accumulator variables: copy, d
Iterator variables: i, j, n
Python program:
from math import sqrt , ceil
N = 10001
v = [ [ ] for i in range ( N ) ]
def preprocess ( ) :
    for i in range ( 1 , N ) :
        num = i
        for j in range ( 2 , ceil ( sqrt ( num ) ) + 1 ) :
            if ( num % j == 0 ) :
                v [ i ] . append ( j )
                while ( num % j == 0 ) :
                    num = num // j
        if ( num > 2 ) :
            v [ i ] . append ( num )
def query ( number , n ) :
    return v [ number ] [ n - 1 ]
preprocess ( )
number = 6
n = 1
print ( query ( number , n ) )
number = 210
n = 3
print ( query ( number , n ) )
number = 210
n = 2
print ( query ( number , n ) )
number = 60
n = 2
print ( query ( number , n ) )

Index/key variables: i, number
Iterator variables: i, j
Python program:
def dig ( a ) :
    count = 0 ;
    while ( a > 0 ) :
        a /= 10
        count += 1
    return count
def required_number ( num , n , d ) :
    flag = 0
    power = 0
    a = 0
    for i in range ( num , 0 , - 1 ) :
        power = pow ( 10 , i )
        a = n % power
        if ( d > a ) :
            flag = 1
            break
    if ( flag ) :
        t = 0
        for j in range ( 0 , i ) :
            t += 9 * pow ( 10 , j )
        if ( n % power == t ) :
            print ( n , end = " " )
        else :
            print ( ( n - ( n % power ) - 1 ) , end = " " )
    else :
        print ( n , end = " " )
if __name__ == " _ _ main _ _ " :
    n = 1029
    d = 102
    num = dig ( n )
    required_number ( num , n , d )

Accumulator variables: a, count, t
Iterator variables: i, j
Python program:
def ways ( n ) :
    first = 2 ;
    second = 3 ;
    res = 0 ;
    for i in range ( 3 , n + 1 ) :
        res = first + second ;
        first = second ;
        second = res ;
    return res ;
n = 7 ;
print ( " Total ▁ ways ▁ are : ▁ " , ways ( n ) ) ;

Iterator variables: i
Python program:
import math
def countDigits ( n ) :
    ans = 0
    for i in range ( 1 , n + 1 ) :
        ans += math . log10 ( i )
    ans = ans * n
    return 1 + math . floor ( ans )
if __name__ == " _ _ main _ _ " :
    n = 4
    print ( countDigits ( n ) )

Accumulator variables: ans
Iterator variables: i
Python program:
def printTwinPrime ( n ) :
    prime = [ True for i in range ( n + 2 ) ]
    p = 2
    while ( p * p <= n + 1 ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * 2 , n + 2 , p ) :
                prime [ i ] = False
        p += 1
    for p in range ( 2 , n - 1 ) :
        if prime [ p ] and prime [ p + 2 ] :
            print ( " ( " , p , " , " , ( p + 2 ) , " ) " , end = ' ' )
if __name__ == ' _ _ main _ _ ' :
    n = 25
    printTwinPrime ( n )

Index/key variables: i, p
Iterator variables: i, p
Python program:
import math
def isCubeFree ( n ) :
    if n == 1 :
        return False
    for i in range ( 2 , int ( n ** ( 1 / 3 ) + 1 ) ) :
        if ( n % ( i * i * i ) == 0 ) :
            return False ;
    return True ;
def printCubeFree ( n ) :
    for i in range ( 2 , n + 1 ) :
        if ( isCubeFree ( i ) ) :
            print ( i , end = " ▁ " )
n = 20
printCubeFree ( n )

Iterator variables: i
Python program:
import math
def productPrimeFactors ( n ) :
    product = 1
    if ( n % 2 == 0 ) :
        product *= 2
        while ( n % 2 == 0 ) :
            n = n / 2
    for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 , 2 ) :
        if ( n % i == 0 ) :
            product = product * i
            while ( n % i == 0 ) :
                n = n / i
    if ( n > 2 ) :
        product = product * n
    return product
n = 44
print ( int ( productPrimeFactors ( n ) ) )

Iterator variables: i
Python program:
import math
def mean ( mid , freq , n ) :
    sum = 0
    freqSum = 0
    for i in range ( 0 , n ) :
        sum = sum + mid [ i ] * freq [ i ]
        freqSum = freqSum + freq [ i ]
    return sum / freqSum
def groupedSD ( lower_limit , upper_limit , freq , n ) :
    mid = [ [ 0 ] for i in range ( 0 , n ) ]
    sum = 0
    freqSum = 0
    sd = 0
    for i in range ( 0 , n ) :
        mid [ i ] = ( lower_limit [ i ] + upper_limit [ i ] ) / 2
        sum = sum + freq [ i ] * mid [ i ] * mid [ i ]
        freqSum = freqSum + freq [ i ]
    sd = math . sqrt ( ( sum - freqSum * mean ( mid , freq , n ) * mean ( mid , freq , n ) ) / ( freqSum - 1 ) )
    return sd
lower_limit = [ 50 , 61 , 71 , 86 , 96 ]
upper_limit = [ 60 , 70 , 85 , 95 , 100 ]
freq = [ 9 , 7 , 9 , 12 , 8 ]
n = len ( lower_limit )
print ( groupedSD ( lower_limit , upper_limit , freq , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def avg_of_even_num ( n ) :
    sum = 0
    for i in range ( 1 , n + 1 ) :
        sum = sum + 2 * i
    return sum / n
n = 9
print ( avg_of_even_num ( n ) )

Iterator variables: i
Python program:
def binomialCoeff ( n , k ) :
    C = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        for j in range ( min ( i , k ) + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1 ;
            else :
                C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;
    return C [ n ] [ k ] ;
def maxcoefficientvalue ( n ) :
    if ( n % 2 == 0 ) :
        return binomialCoeff ( n , int ( n / 2 ) ) ;
    else :
        return binomialCoeff ( n , int ( ( n + 1 ) / 2 ) ) ;
if __name__ == ' _ _ main _ _ ' :
    n = 4 ;
    print ( maxcoefficientvalue ( n ) ) ;

Index/key variables: i, j, k, n
Iterator variables: i, j
Python program:
def accumulate ( s ) :
    acc = 0 ;
    for i in range ( len ( s ) ) :
        acc += ord ( s [ i ] ) - 48 ;
    return acc ;
def isDivisible ( s ) :
    n = len ( s ) ;
    if ( s [ n - 1 ] != '5' and s [ n - 1 ] != '0' ) :
        return False ;
    sum = accumulate ( s ) ;
    return ( sum % 3 == 0 ) ;
s = "15645746327462384723984023940239" ;
if isDivisible ( s ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;
s = "15645746327462384723984023940235" ;
if isDivisible ( s ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;

Index/key variables: i
Accumulator variables: acc
Iterator variables: i
Python program:
V = 4
INF = 999999999999
def shortestPath ( graph , u , v , k ) :
    if k == 0 and u == v :
        return 0
    if k == 1 and graph [ u ] [ v ] != INF :
        return graph [ u ] [ v ]
    if k <= 0 :
        return INF
    res = INF
    for i in range ( V ) :
        if graph [ u ] [ i ] != INF and u != i and v != i :
            rec_res = shortestPath ( graph , i , v , k - 1 )
            if rec_res != INF :
                res = min ( res , graph [ u ] [ i ] + rec_res )
    return res
if __name__ == ' _ _ main _ _ ' :
    INF = 999999999999
    graph = [ [ 0 , 10 , 3 , 2 ] , [ INF , 0 , INF , 7 ] , [ INF , INF , 0 , 6 ] , [ INF , INF , INF , 0 ] ]
    u = 0
    v = 3
    k = 2
    print ( " Weight ▁ of ▁ the ▁ shortest ▁ path ▁ is " , shortestPath ( graph , u , v , k ) )

Index/key variables: i, u, v
Iterator variables: i
Python program:
V = 4
INF = 999999999999
def shortestPath ( graph , u , v , k ) :
    global V , INF
    sp = [ [ None ] * V for i in range ( V ) ]
    for i in range ( V ) :
        for j in range ( V ) :
            sp [ i ] [ j ] = [ None ] * ( k + 1 )
    for e in range ( k + 1 ) :
        for i in range ( V ) :
            for j in range ( V ) :
                sp [ i ] [ j ] [ e ] = INF
                if ( e == 0 and i == j ) :
                    sp [ i ] [ j ] [ e ] = 0
                if ( e == 1 and graph [ i ] [ j ] != INF ) :
                    sp [ i ] [ j ] [ e ] = graph [ i ] [ j ]
                if ( e > 1 ) :
                    for a in range ( V ) :
                        if ( graph [ i ] [ a ] != INF and i != a and j != a and sp [ a ] [ j ] [ e - 1 ] != INF ) :
                            sp [ i ] [ j ] [ e ] = min ( sp [ i ] [ j ] [ e ] , graph [ i ] [ a ] + sp [ a ] [ j ] [ e - 1 ] )
    return sp [ u ] [ v ] [ k ]
graph = [ [ 0 , 10 , 3 , 2 ] , [ INF , 0 , INF , 7 ] , [ INF , INF , 0 , 6 ] , [ INF , INF , INF , 0 ] ]
u = 0
v = 3
k = 2
print ( " Weight ▁ of ▁ the ▁ shortest ▁ path ▁ is " , shortestPath ( graph , u , v , k ) )

Index/key variables: a, e, i, j, k, u, v
Iterator variables: a, e, i, j
Python program:
def shortestDist ( graph ) :
    global INF
    dist = [ 0 ] * N
    dist [ N - 1 ] = 0
    for i in range ( N - 2 , - 1 , - 1 ) :
        dist [ i ] = INF
        for j in range ( N ) :
            if graph [ i ] [ j ] == INF :
                continue
            dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] )
    return dist [ 0 ]
N = 8
INF = 999999999999
graph = [ [ INF , 1 , 2 , 5 , INF , INF , INF , INF ] , [ INF , INF , INF , INF , 4 , 11 , INF , INF ] , [ INF , INF , INF , INF , 9 , 5 , 16 , INF ] , [ INF , INF , INF , INF , INF , INF , 2 , INF ] , [ INF , INF , INF , INF , INF , INF , INF , 18 ] , [ INF , INF , INF , INF , INF , INF , INF , 13 ] , [ INF , INF , INF , INF , INF , INF , INF , 2 ] ]
print ( shortestDist ( graph ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
class edge :
    def __init__ ( self , u , w ) :
        self . From = u
        self . weight = w
def addedge ( u , v , w ) :
    edges [ v ] . append ( edge ( u , w ) )
V = 4
edges = [ [ ] for i in range ( V ) ]
def shortestpath ( dp ) :
    for i in range ( V + 1 ) :
        for j in range ( V ) :
            dp [ i ] [ j ] = - 1
    dp [ 0 ] [ 0 ] = 0
    for i in range ( 1 , V + 1 ) :
        for j in range ( V ) :
            for k in range ( len ( edges [ j ] ) ) :
                if ( dp [ i - 1 ] [ edges [ j ] [ k ] . From ] != - 1 ) :
                    curr_wt = ( dp [ i - 1 ] [ edges [ j ] [ k ] . From ] + edges [ j ] [ k ] . weight )
                    if ( dp [ i ] [ j ] == - 1 ) :
                        dp [ i ] [ j ] = curr_wt
                    else :
                        dp [ i ] [ j ] = min ( dp [ i ] [ j ] , curr_wt )
def minAvgWeight ( ) :
    dp = [ [ None ] * V for i in range ( V + 1 ) ]
    shortestpath ( dp )
    avg = [ - 1 ] * V
    for i in range ( V ) :
        if ( dp [ V ] [ i ] != - 1 ) :
            for j in range ( V ) :
                if ( dp [ j ] [ i ] != - 1 ) :
                    avg [ i ] = max ( avg [ i ] , ( dp [ V ] [ i ] - dp [ j ] [ i ] ) / ( V - j ) )
    result = avg [ 0 ]
    for i in range ( V ) :
        if ( avg [ i ] != - 1 and avg [ i ] < result ) :
            result = avg [ i ]
    return result
addedge ( 0 , 1 , 1 )
addedge ( 0 , 2 , 10 )
addedge ( 1 , 2 , 3 )
addedge ( 2 , 3 , 2 )
addedge ( 3 , 1 , 0 )
addedge ( 3 , 0 , 8 )
print ( minAvgWeight ( ) )

Index/key variables: V, i, j, k, v
Iterator variables: i, j, k
Class/struct names: edge
Python program:
import numpy
def findCount ( s ) :
    freq = [ 0 ] * 26
    dp = [ [ 0 ] * 26 ] * 26
    freq = numpy . zeros ( 26 )
    dp = numpy . zeros ( [ 26 , 26 ] )
    for i in range ( 0 , len ( s ) ) :
        for j in range ( 26 ) :
            dp [ j ] [ ord ( s [ i ] ) - ord ( ' a ' ) ] += freq [ j ]
        freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    ans = 0
    for i in range ( 26 ) :
        ans = max ( freq [ i ] , ans )
    for i in range ( 0 , 26 ) :
        for j in range ( 0 , 26 ) :
            ans = max ( dp [ i ] [ j ] , ans )
    return int ( ans )
str = " acbab "
print ( findCount ( str ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def constructArray ( N , K , X ) :
    ans = [ ]
    for i in range ( 0 , K ) :
        ans . append ( 0 )
    ans [ 0 ] = X
    for i in range ( 0 , N ) :
        print ( ans [ i % K ] , end = " ▁ " )
N = 5
K = 2
X = 4
constructArray ( N , K , X )

Accumulator variables: ans
Iterator variables: i
Python program:
from collections import defaultdict
def game ( v , n ) :
    m = defaultdict ( int )
    for i in range ( n ) :
        if ( v [ i ] not in m ) :
            m [ v [ i ] ] = 1
        else :
            m [ v [ i ] ] += 1
    count = 0
    check = 0
    for i in m . values ( ) :
        if ( i > 1 ) :
            if ( i >= 4 and i % 2 == 0 ) :
                check += 1
            count += 1
    if ( check % 2 != 0 ) :
        flag = False
    if ( check % 2 != 0 ) :
        print ( " Yes " )
    elif ( n % 2 == 0 and count % 2 == 0 ) :
        print ( " No " )
    else :
        print ( " Yes " )
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 2 , 2 , 3 , 3 , 5 ]
    size = len ( arr )
    game ( arr , size )

Index/key variables: i
Accumulator variables: check, count
Iterator variables: i
Boolean variables: flag
Python program:
import math
mod = 1000000007
def solve ( A , n ) :
    cnt = 0
    parent = [ - 1 ] * n
    vis = [ 0 ] * n
    for i in range ( n ) :
        j = i
        if ( parent [ j ] == - 1 ) :
            while ( parent [ j ] == - 1 ) :
                parent [ j ] = i
                j = math . gcd ( j , A [ j ] ) % n
            if ( parent [ j ] == i ) :
                while ( vis [ j ] == 0 ) :
                    vis [ j ] = 1
                    cnt += 1
                    j = math . gcd ( j , A [ j ] ) % n
    return cnt
A = [ 1 , 1 , 6 , 2 ]
n = len ( A )
print ( solve ( A , n ) )

Index/key variables: j
Accumulator variables: cnt
Iterator variables: i
Python program:
def AddEdge ( u , v ) :
    global adj
    adj [ u ] . append ( v )
    adj [ v ] . append ( u )
def findFirstEnd ( u , p ) :
    global lvl , adj , end1 , maxi
    lvl [ u ] = 1 + lvl [ p ]
    if ( lvl [ u ] > maxi ) :
        maxi = lvl [ u ]
        end1 = u
    for i in range ( len ( adj [ u ] ) ) :
        if ( adj [ u ] [ i ] != p ) :
            findFirstEnd ( adj [ u ] [ i ] , u )
def clear ( n ) :
    global lvl , dist1 , dist2
    for i in range ( n + 1 ) :
        lvl [ i ] = 0
    maxi = 0
    dist1 [ 0 ] = dist2 [ 0 ] = - 1
def findSecondEnd ( u , p ) :
    global lvl , adj , maxi , end2
    lvl [ u ] = 1 + lvl [ p ]
    if ( lvl [ u ] > maxi ) :
        maxi = lvl [ u ]
        end2 = u
    for i in range ( len ( adj [ u ] ) ) :
        if ( adj [ u ] [ i ] != p ) :
            findSecondEnd ( adj [ u ] [ i ] , u )
def findDistancefromFirst ( u , p ) :
    global dist1 , adj
    dist1 [ u ] = 1 + dist1 [ p ]
    for i in range ( len ( adj [ u ] ) ) :
        if ( adj [ u ] [ i ] != p ) :
            findDistancefromFirst ( adj [ u ] [ i ] , u )
def findDistancefromSecond ( u , p ) :
    global dist2 , adj
    dist2 [ u ] = 1 + dist2 [ p ]
    for i in range ( len ( adj [ u ] ) ) :
        if ( adj [ u ] [ i ] != p ) :
            findDistancefromSecond ( adj [ u ] [ i ] , u )
def findNodes ( ) :
    global adj , lvl , dist1 , dist2 , end1 , end2 , maxi
    n = 5
    AddEdge ( 1 , 2 )
    AddEdge ( 1 , 3 )
    AddEdge ( 3 , 4 )
    AddEdge ( 3 , 5 )
    findFirstEnd ( 1 , 0 )
    clear ( n )
    findSecondEnd ( end1 , 0 )
    findDistancefromFirst ( end1 , 0 )
    findDistancefromSecond ( end2 , 0 )
    for i in range ( 1 , n + 1 ) :
        x = dist1 [ i ]
        y = dist2 [ i ]
        if ( x >= y ) :
            print ( end1 , end = " ▁ " )
        else :
            print ( end2 , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    adj = [ [ ] for i in range ( 10000 ) ]
    lvl = [ 0 for i in range ( 10000 ) ]
    dist1 = [ - 1 for i in range ( 10000 ) ]
    dist2 = [ - 1 for i in range ( 10000 ) ]
    end1 , end2 , maxi = 0 , 0 , 0
    findNodes ( )

Index/key variables: i, p, u, v
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . next = None
def push ( head_ref , new_data ) :
    new_node = Node ( new_data )
    new_node . next = head_ref
    head_ref = new_node
    return head_ref
def digitSum ( num ) :
    sum = 0
    while ( num ) :
        sum += ( num % 10 )
        num //= 10
    return sum
def sumAndProduct ( head_ref ) :
    prod = 1
    sum = 0
    ptr = head_ref
    while ( ptr != None ) :
        if ( not ( digitSum ( ptr . data ) & 1 ) ) :
            prod *= ptr . data
            sum += ptr . data
        ptr = ptr . next
    print ( " Sum ▁ = " , sum )
    print ( " Product ▁ = " , prod )
if __name__ == ' _ _ main _ _ ' :
    head = None
    head = push ( head , 13 )
    head = push ( head , 6 )
    head = push ( head , 8 )
    head = push ( head , 16 )
    head = push ( head , 15 )
    sumAndProduct ( head )

Accumulator variables: num, prod, sum
Class/struct names: Node
Python program:
def ShortestPalindrome ( s ) :
    n = len ( s )
    v = [ ]
    for i in range ( n ) :
        l = i
        r = i
        ans1 = " "
        ans2 = " "
        while ( ( l >= 0 ) and ( r < n ) and ( s [ l ] == s [ r ] ) ) :
            ans1 += s [ l ]
            l -= 1
            r += 1
        l = i - 1
        r = i
        while ( ( l >= 0 ) and ( r < n ) and ( s [ l ] == s [ r ] ) ) :
            ans2 += s [ l ]
            l -= 1
            r += 1
        v . append ( ans1 )
        v . append ( ans2 )
    ans = v [ 0 ]
    for i in range ( len ( v ) ) :
        if ( v [ i ] != " " ) :
            ans = min ( ans , v [ i ] )
    return ans
s = " geeksforgeeks "
print ( ShortestPalindrome ( s ) )

Index/key variables: i, l, r
Accumulator variables: ans1, ans2, v
Iterator variables: i
Python program:
from math import gcd
def lcm ( x , y ) :
    temp = ( x * y ) // gcd ( x , y ) ;
    return temp ;
def findNumbers ( a , n , b , m ) :
    lcmA = 1 ; __gcdB = 0 ;
    for i in range ( n ) :
        lcmA = lcm ( lcmA , a [ i ] ) ;
    for i in range ( m ) :
        __gcdB = gcd ( __gcdB , b [ i ] ) ;
    if ( __gcdB % lcmA != 0 ) :
        print ( " - 1" ) ;
        return ;
    num = lcmA ;
    while ( num <= __gcdB ) :
        if ( __gcdB % num == 0 ) :
            print ( num , end = " ▁ " ) ;
        num += lcmA ;
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 2 , 4 ] ;
    b = [ 16 , 32 , 64 ] ;
    n = len ( a ) ;
    m = len ( b ) ;
    findNumbers ( a , n , b , m ) ;

Index/key variables: i
Accumulator variables: num
Iterator variables: i
Python program:
import math
def binomialCoeff ( n , k ) :
    res = 1
    if ( k > n - k ) :
        k = n - k
    for i in range ( 0 , k ) :
        res = res * ( n - i )
        res = res // ( i + 1 )
    return res
def power ( x , y ) :
    res = 1
    while ( y > 0 ) :
        if ( y & 1 ) :
            res = res * x
        y = y // 2
        x = x * x
    return res
def FindProbability ( n ) :
    up = binomialCoeff ( 2 * n , n )
    down = power ( 2 , 2 * n )
    g = math . gcd ( up , down )
    up = up // g
    down = down // g
    print ( up , " / " , down )
N = 8
FindProbability ( N )

Iterator variables: i
Python program:
N = 4
print ( " Value ▁ of ▁ N : ▁ " , N )
for i in range ( 1 , N + 1 ) :
    for j in range ( 1 , N + 1 ) :
        min = i if i < j else j
        print ( N - min + 1 , end = " ▁ " )
    for j in range ( N - 1 , 0 , - 1 ) :
        min = i if i < j else j
        print ( N - min + 1 , end = " ▁ " )
    print ( )
for i in range ( N - 1 , 0 , - 1 ) :
    for j in range ( 1 , N + 1 ) :
        min = i if i < j else j
        print ( N - min + 1 , end = " ▁ " )
    for j in range ( N - 1 , 0 , - 1 ) :
        min = i if i < j else j
        print ( N - min + 1 , end = " ▁ " )
    print ( )

Iterator variables: i, j
Python program:
from math import sqrt
def checkPerfectSquare ( n ) :
    d = sqrt ( n )
    if d * d == n :
        return True
    return False
def largestPerfectSquareNumber ( a , n ) :
    maxi = - 1
    for i in range ( n ) :
        if ( checkPerfectSquare ( a [ i ] ) ) :
            maxi = max ( a [ i ] , maxi )
    return maxi
if __name__ == " _ _ main _ _ " :
    a = [ 16 , 20 , 25 , 2 , 3 , 10 ]
    n = len ( a )
    print ( largestPerfectSquareNumber ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def convert ( n , a ) :
    z = max ( a ) + 1
    ff = [ 0 ] * z
    for i in range ( n ) :
        ff [ a [ i ] ] += 1
    cc = 0
    for i in range ( z ) :
        cc += ff [ i ] // 4
        ff [ i ] = ff [ i ] % 4
    vv = 0
    for i in range ( z ) :
        if ( ff [ i ] >= 2 ) :
            vv += 1
    cc += vv // 2
    print ( cc )
n = 4
a = [ 1 , 2 , 1 , 2 ]
convert ( n , a )

Index/key variables: i
Accumulator variables: cc, vv
Iterator variables: i
Python program:
from math import gcd
def find_LCM ( x , y ) :
    return ( x * y ) // gcd ( x , y )
def CountPairs ( n , m , A , B ) :
    cnt = 0
    lcm = find_LCM ( A , B )
    for i in range ( 1 , n + 1 ) :
        cnt += ( m + ( i % lcm ) ) // lcm
    return cnt
if __name__ == " _ _ main _ _ " :
    n , m , A , B = 60 , 90 , 5 , 10
    print ( CountPairs ( n , m , A , B ) )

Accumulator variables: cnt
Iterator variables: i
Python program:
def sortArr ( arr , n , min_no , max_no ) :
    m = max_no - min_no + 1
    c = [ 0 ] * m
    for i in range ( n ) :
        c [ arr [ i ] - min_no ] += 1
    for i in range ( m ) :
        for j in range ( ( c [ i ] ) ) :
            print ( ( i + min_no ) , end = " ▁ " )
arr = [ 10 , 10 , 1 , 4 , 4 , 100 , 0 ]
min_no , max_no = 0 , 100
n = len ( arr )
sortArr ( arr , n , min_no , max_no )

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