dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from math import log2 , floor
def maxOR ( arr , n ) :
    max_value = max ( arr )
    number_of_bits = floor ( log2 ( max_value ) ) + 1
    complement = ( ( ( 1 << number_of_bits ) - 1 ) ^ max_value )
    c = 0
    for i in range ( n ) :
        if ( arr [ i ] != max_value ) :
            c = max ( c , ( complement & arr [ i ] ) )
    return ( max_value + c )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 6 , 8 , 16 ]
    n = len ( arr )
    print ( maxOR ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def update ( res , L , R , K ) :
    L = L - 1
    R = R - 1
    res [ L ] = res [ L ] ^ K
    res [ R + 1 ] = res [ R + 1 ] ^ K
def display ( arr , res , n ) :
    for i in range ( 1 , n ) :
        res [ i ] = res [ i ] ^ res [ i - 1 ]
    for i in range ( 0 , n ) :
        print ( arr [ i ] ^ res [ i ] , end = " ▁ " )
arr = [ 2 , 4 , 6 , 8 , 10 ]
N = len ( arr )
res = [ 0 ] * N
L = 1
R = 3
K = 2
update ( res , L , R , K )
L = 2
R = 4
K = 3
update ( res , L , R , K )
display ( arr , res , N )

Index/key variables: L, i
Iterator variables: i
Python program:
from collections import defaultdict
def check ( a , n , k ) :
    m = defaultdict ( int )
    extra = 0
    for i in range ( k , n ) :
        m [ a [ i ] ] += 1
    for x in m :
        extra += m [ x ] - 1
    if ( extra == 0 ) :
        return True
    for i in range ( 1 , i + k - 1 < n ) :
        if ( m [ a [ i + k - 1 ] ] > 1 ) :
            extra -= 1
        m [ a [ i + k - 1 ] ] -= 1
        m [ a [ i - 1 ] ] += 1
        if ( m [ a [ i - 1 ] ] > 1 ) :
            extra += 1
        if ( extra == 0 ) :
            return True
    return False
def minlength ( a , n ) :
    lo = 0
    hi = n + 1
    ans = 0
    while ( lo < hi ) :
        mid = ( lo + hi ) // 2
        if ( check ( a , n , mid ) ) :
            ans = mid
            hi = mid
        else :
            lo = mid + 1
    return ans
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 1 , 2 , 3 ]
    n = len ( a )
    print ( minlength ( a , n ) )

Index/key variables: i, x
Accumulator variables: extra
Iterator variables: i, x
Python program:
def findNumbers ( N ) :
    for i in range ( 1 , N // 2 + 1 ) :
        print ( i , end = ' , ▁ ' )
        print ( - i , end = ' , ▁ ' )
    if N % 2 == 1 :
        print ( 0 , end = ' ' )
if __name__ == ' _ _ main _ _ ' :
    N = 10
    findNumbers ( N )

Iterator variables: i
Python program:
import math
def countPrimeFactors ( n ) :
    if ( n == 1 ) :
        return 0
    cnt = 0
    while ( n % 2 == 0 ) :
        cnt += 1
        n = n // 2
    for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 , 2 ) :
        while ( n % i == 0 ) :
            cnt += 1
            n = n // i
    if ( n > 2 ) :
        cnt += 1
    return cnt
x = 8
prime_factor_cnt = countPrimeFactors ( x )
print ( prime_factor_cnt )

Accumulator variables: cnt
Iterator variables: i
Python program:
def countSubArrayWithOddProduct ( A , N ) :
    count = 0
    last = - 1
    K = 0
    for i in range ( N ) :
        if ( A [ i ] % 2 == 0 ) :
            K = ( i - last - 1 )
            count += ( K * ( K + 1 ) / 2 )
            last = i
    K = ( N - last - 1 )
    count += ( K * ( K + 1 ) / 2 )
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 15 , 7 , 3 , 25 , 6 , 2 , 1 , 1 , 7 ]
    n = len ( arr )
    print ( int ( countSubArrayWithOddProduct ( arr , n ) ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findMinXORSubarray ( arr , n , k ) :
    if ( n < k ) :
        return
    res_index = 0
    curr_xor = 0
    for i in range ( 0 , k ) :
        curr_xor = curr_xor ^ arr [ i ]
    min_xor = curr_xor
    for i in range ( k , n ) :
        curr_xor ^= ( arr [ i ] ^ arr [ i - k ] )
        if ( curr_xor < min_xor ) :
            min_xor = curr_xor
            res_index = ( i - k + 1 )
    print ( min_xor , end =   ' ' )
arr = [ 3 , 7 , 90 , 20 , 10 , 50 , 40 ]
k = 3
n = len ( arr )
findMinXORSubarray ( arr , n , k )

Index/key variables: i
Accumulator variables: curr_xor
Iterator variables: i
Python program:
import sys ;
def getNumber ( a , b ) :
    X = str ( a ) ;
    Y = str ( b ) ;
    XY = X + Y ;
    YX = Y + X ;
    if ( XY > YX ) :
        return XY ;
    else :
        return YX ;
def printMaxPair ( arr , n ) :
    largest = - sys . maxsize - 1 ;
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            number = int ( getNumber ( arr [ i ] , arr [ j ] ) ) ;
            largest = max ( largest , number ) ;
    print ( largest ) ;
a = [ 23 , 14 , 16 , 25 , 3 , 9 ] ;
n = len ( a ) ;
printMaxPair ( a , n ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findCount ( arr , n ) :
    res = 0
    for i in range ( 0 , n - 1 ) :
        for j in range ( i + 1 , n ) :
            if ( ( arr [ i ] % 2 == 0 ) and ( arr [ j ] % 2 == 1 ) ) :
                res = res + 1
    return res
a = [ 5 , 4 , 1 , 2 , 3 ]
n = len ( a )
print ( findCount ( a , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findCount ( arr , n ) :
    count = 0
    ans = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] % 2 == 0 ) :
            count = count + 1
        else :
            ans = ans + count
    return ans
a = [ 5 , 4 , 1 , 2 , 3 ]
n = len ( a )
print ( findCount ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def product ( arr ) :
    occurrence = pow ( 2 , len ( arr ) - 1 ) ;
    product = 1 ;
    for i in range ( 0 , len ( arr ) ) :
        product *= pow ( arr [ i ] , occurrence ) ;
    return product ;
arr = [ 10 , 3 , 7 ] ;
print ( product ( arr ) ) ;

Index/key variables: i
Accumulator variables: product
Iterator variables: i
Python program:
MOD = 1000000007
def power ( a , b ) :
    if ( b == 0 ) :
        return 1
    temp = power ( a , b // 2 )
    temp = ( temp * temp ) % MOD
    if ( b % 2 != 0 ) :
        temp = ( temp * a ) % MOD
    return temp
def palindromicSum ( N ) :
    sum = 0
    if ( N == 1 ) :
        print ( "9" )
        return
    if ( N == 2 ) :
        print ( "99" )
        return
    ways = N // 2
    if ( N % 2 == 0 ) :
        ways -= 1
    res = power ( 9 , ways - 1 )
    for i in range ( N ) :
        sum = sum * 10 + 45 * res
        sum %= MOD
    print ( sum )
if __name__ == " _ _ main _ _ " :
    N = 3
    palindromicSum ( N )

Accumulator variables: sum
Iterator variables: i
Python program:
def joinNumbers ( numA , numB ) :
    revB = 0
    while ( numB > 0 ) :
        revB = revB * 10 + ( numB % 10 )
        numB = numB // 10
    while ( revB > 0 ) :
        numA = numA * 10 + ( revB % 10 )
        revB = revB // 10
    return numA
def findMaxSum ( A , B , n ) :
    maxArr = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        X = joinNumbers ( A [ i ] , B [ i ] )
        Y = joinNumbers ( B [ i ] , A [ i ] )
        mx = max ( X , Y )
        maxArr [ i ] = mx
    maxAns = 0
    for i in range ( n ) :
        maxAns += maxArr [ i ]
    return maxAns
if __name__ == ' _ _ main _ _ ' :
    N = 5
    A = [ 11 , 23 , 38 , 43 , 59 ]
    B = [ 36 , 24 , 17 , 40 , 56 ]
    print ( findMaxSum ( A , B , N ) )

Index/key variables: i
Accumulator variables: maxAns
Iterator variables: i
Python program:
def createSets ( n ) :
    if ( n <= 2 ) :
        print ( " - 1" ) ;
        return ;
    else :
        x = ( n // 2 ) if ( n % 2 == 0 ) else ( ( n + 1 ) // 2 ) ;
        print ( x , " ▁ " ) ;
        for i in range ( 1 , n + 1 ) :
            if ( i == x ) :
                continue ;
            print ( i , end = " ▁ " ) ;
    return ;
if __name__ == ' _ _ main _ _ ' :
    N = 7 ;
    createSets ( N ) ;

Iterator variables: i
Python program:
def calcCount ( arr , n , k ) :
    count = 0
    for i in range ( 0 , n ) :
        if ( k % arr [ i ] == 0 ) :
            count = count + 1
    return count
arr = [ 1 , 2 , 4 , 5 , 6 ]
n = len ( arr )
k = 6
print ( calcCount ( arr , n , k ) )

Index/key variables: i
Iterator variables: i
Python program:
def findnum ( s1 ) :
    v = [ ]
    a = 0
    b = 0
    sa = 0
    sb = 0
    i = 0
    if ( s1 [ 0 ] == ' - ' ) :
        sa = 1
        i = 1
    while ( s1 [ i ] . isdigit ( ) ) :
        a = a * 10 + ( int ( s1 [ i ] ) )
        i += 1
    if ( s1 [ i ] == ' + ' ) :
        sb = 0
        i += 1
    if ( s1 [ i ] == ' - ' ) :
        sb = 1
        i += 1
    while ( i < len ( s1 ) and s1 [ i ] . isdigit ( ) ) :
        b = b * 10 + ( int ( s1 [ i ] ) )
        i += 1
    if ( sa ) :
        a *= - 1
    if ( sb ) :
        b *= - 1
    v . append ( a )
    v . append ( b )
    return v
def complexNumberMultiply ( v ) :
    while ( len ( v ) != 1 ) :
        v1 = findnum ( v [ 0 ] )
        v2 = findnum ( v [ 1 ] )
        del v [ 0 ]
        del v [ 0 ]
        r = ( v1 [ 0 ] * v2 [ 0 ] - v1 [ 1 ] * v2 [ 1 ] )
        img = v1 [ 0 ] * v2 [ 1 ] + v1 [ 1 ] * v2 [ 0 ]
        res = " "
        res += str ( r )
        res += ' + '
        res += str ( img ) + ' i '
        v . insert ( 0 , res )
    return v [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    n = 3
    v = [ "3 + 1i " , "2 + 1i " , " - 5 + - 7i " ]
    print ( complexNumberMultiply ( v ) )

Index/key variables: i
Accumulator variables: res
Python program:
def isPerfect ( n ) :
    sum = 1
    i = 2
    while i * i <= n :
        if n % i == 0 :
            sum = sum + i + n / i
        i += 1
    return ( True if sum == n and n != 1 else False )
def contiguousPerfectNumber ( arr , n ) :
    current_length = 0
    max_length = 0
    for i in range ( 0 , n , 1 ) :
        if ( isPerfect ( arr [ i ] ) ) :
            current_length += 1
        else :
            current_length = 0
        max_length = max ( max_length , current_length )
    return max_length
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 7 , 36 , 4 , 6 , 28 , 4 ]
    n = len ( arr )
    print ( contiguousPerfectNumber ( arr , n ) )

Index/key variables: i
Accumulator variables: current_length
Iterator variables: i
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 )
def contiguousPowerfulNumber ( arr , n ) :
    current_length = 0
    max_length = 0
    for i in range ( 0 , n , 1 ) :
        if ( isPowerful ( arr [ i ] ) ) :
            current_length += 1
        else :
            current_length = 0
        max_length = max ( max_length , current_length )
    return max_length
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 7 , 36 , 4 , 6 , 28 , 4 ]
    n = len ( arr )
    print ( contiguousPowerfulNumber ( arr , n ) )

Index/key variables: i
Accumulator variables: current_length
Iterator variables: factor, i
Python program:
def maxSum ( arr , K , start , end , max_sum ) :
    if ( K == 0 ) :
        return max_sum
    max_sum_start = max_sum + arr [ start ]
    max_sum_end = max_sum + arr [ end ]
    ans = max ( maxSum ( arr , K - 1 , start + 1 , end , max_sum_start ) , maxSum ( arr , K - 1 , start , end - 1 , max_sum_end ) )
    return ans
def maximizeSum ( arr , K , n ) :
    max_sum = 0
    start = 0
    end = n - 1
    print ( maxSum ( arr , K , start , end , max_sum ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 8 , 4 , 4 , 8 , 12 , 3 , 2 , 9 ]
    K = 3
    n = len ( arr )
    maximizeSum ( arr , K , n )

Index/key variables: end, start
Python program:
def maxPointCount ( arr , K , size ) :
    curr_points = 0
    max_points = 0
    for i in range ( K ) :
        curr_points += arr [ i ]
    max_points = curr_points
    j = size - 1
    for i in range ( K - 1 , - 1 , - 1 ) :
        curr_points = ( curr_points + arr [ j ] - arr [ i ] )
        max_points = max ( curr_points , max_points )
        j -= 1
    return max_points
if __name__ == " _ _ main _ _ " :
    arr = [ 8 , 4 , 4 , 8 , 12 , 3 , 2 , 9 ]
    K = 3
    n = len ( arr )
    print ( maxPointCount ( arr , K , n ) )

Index/key variables: i, j
Accumulator variables: curr_points
Iterator variables: i
Python program:
def countPalindrome ( n ) :
    count = 0
    if ( n % 2 == 1 ) :
        count = pow ( 9 , ( n - 1 ) // 2 )
    else :
        count = pow ( 9 , ( n - 2 ) // 2 )
    return count
def sumPalindrome ( n ) :
    count = countPalindrome ( n )
    res = 0
    if ( n == 1 ) :
        return 9
    if ( n == 2 ) :
        return 99
    for i in range ( n ) :
        res = res * 10 + count * 5
    return res
n = 3
print ( sumPalindrome ( n ) )

Iterator variables: i
Python program:
from math import pow
def count ( N , B ) :
    sum = 0
    for i in range ( 1 , N + 1 ) :
        sum += ( B - 1 ) * pow ( B , i - 1 )
    return sum
if __name__ == ' _ _ main _ _ ' :
    N = 2
    B = 10
    print ( int ( count ( N , B ) ) )

Accumulator variables: sum
Iterator variables: i
Python program:
import math
def SmallestPerfectSquare ( N ) :
    X = 1e9
    for i in range ( 1 , int ( math . sqrt ( N ) ) + 1 ) :
        if N % i == 0 :
            a = i
            b = N // i
            if b - a != 0 and ( b - a ) % 2 == 0 :
                X = min ( X , ( b - a ) // 2 )
    return ( X * X if X != 1e9 else - 1 )
if __name__ == " _ _ main _ _ " :
    N = 3
    print ( SmallestPerfectSquare ( N ) )

Iterator variables: i
Python program:
def minCost ( arr , n , circumference ) :
    arr . sort ( )
    arr2 = [ 0 ] * ( 2 * n )
    for i in range ( n ) :
        arr2 [ i ] = arr [ i ]
        arr2 [ i + n ] = arr [ i ] + circumference
    res = 9999999999999999999 ;
    for i in range ( n ) :
        res = min ( res , arr2 [ i + ( n - 1 ) ] - arr2 [ i ] ) ;
    return res ;
arr = [ 19 , 3 , 6 ] ;
n = len ( arr )
circumference = 20 ;
print ( minCost ( arr , n , circumference ) )

Index/key variables: i
Iterator variables: i
Python program:
def findunique ( a , k ) :
    res = 0
    for i in range ( 32 ) :
        p = 0
        for j in range ( len ( a ) ) :
            if ( abs ( a [ j ] ) & ( 1 << i ) ) != 0 :
                p += 1
        p %= k
        res += pow ( 2 , i ) * p
    c = 0
    for x in a :
        if ( x == res ) :
            c = 1
            break
    if c == 1 :
        return res
    else :
        return - res
a = [ 12 , 12 , 2 , 2 , 3 ]
k = 2
print ( findunique ( a , k ) )

Index/key variables: j
Accumulator variables: p, res
Iterator variables: i, j, x
Python program:
from math import gcd
def MinimumGCD ( arr , n ) :
    g = 0
    for i in range ( n ) :
        g = gcd ( g , arr [ i ] )
    return g
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 6 , 8 , 3 ]
    N = len ( arr )
    print ( MinimumGCD ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def stepRequired ( N ) :
    cnt = 0 ;
    while ( N > 0 ) :
        N = N & ( N - 1 ) ;
        cnt += 1 ;
    return cnt ;
if __name__ == ' _ _ main _ _ ' :
    N = 23 ;
    print ( stepRequired ( N ) ) ;

Accumulator variables: cnt
Python program:
import math
def isPerfectSquare ( x ) :
    s = int ( math . sqrt ( x ) )
    if s * s == x :
        return True
    return False
def isFibonacci ( n ) :
    return ( isPerfectSquare ( 5 * n * n + 4 ) or isPerfectSquare ( 5 * n * n - 4 ) )
def fibonacciSubarrays ( arr , n ) :
    count = 0
    for i in range ( n ) :
        sum = 0
        for j in range ( i , n ) :
            sum += arr [ j ]
            if ( isFibonacci ( sum ) ) :
                count += 1
    print ( count )
arr = [ 6 , 7 , 8 , 9 ]
n = len ( arr )
fibonacciSubarrays ( arr , n )

Index/key variables: j
Accumulator variables: count, sum
Iterator variables: i, j
Python program:
mod = 1000000007
factorial = [ 0 for i in range ( 100005 ) ]
def StoreFactorials ( n ) :
    factorial [ 0 ] = 1
    for i in range ( 1 , n + 1 , 1 ) :
        factorial [ i ] = ( i * factorial [ i - 1 ] ) % mod
def Power ( x , y ) :
    ans = 1
    while ( y > 0 ) :
        if ( y % 2 == 1 ) :
            ans = ( ans * x ) % mod
        x = ( x * x ) % mod
        y //= 2
    return ans
def invmod ( x ) :
    return Power ( x , mod - 2 )
def nCr ( n , r ) :
    return ( ( factorial [ n ] * invmod ( ( factorial [ r ] * factorial [ n - r ] ) % mod ) ) % mod )
def CountWays ( n , k ) :
    StoreFactorials ( n )
    ans = 0
    i = k
    while ( i >= 0 ) :
        if ( i % 2 == k % 2 ) :
            ans = ( ( ans + ( Power ( i , n ) * nCr ( k , i ) ) % mod ) % mod )
        else :
            ans = ( ( ans + mod - ( Power ( i , n ) * nCr ( k , i ) ) % mod ) % mod )
        i -= 1
    ans = ( ans * nCr ( n , k ) ) % mod
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 5
    K = 5
    print ( CountWays ( N , K ) )

Index/key variables: i, n, r
Accumulator variables: y
Iterator variables: i
Python program:
def XOROfElements ( arr , n ) :
    FirstHalfXOR = 0 ;
    SecondHalfXOR = 0 ;
    for i in range ( n ) :
        if ( i < n // 2 ) :
            FirstHalfXOR ^= arr [ i ] ;
        else :
            SecondHalfXOR ^= arr [ i ] ;
    print ( FirstHalfXOR , " , " , SecondHalfXOR ) ;
arr = [ 20 , 30 , 50 , 10 , 55 , 15 , 42 ] ;
N = len ( arr ) ;
XOROfElements ( arr , N ) ;

Index/key variables: i
Accumulator variables: FirstHalfXOR, SecondHalfXOR
Iterator variables: i
Python program:
N = 100005
phi = [ 0 for i in range ( N ) ]
pref = [ 0 for i in range ( N ) ]
def precompute ( ) :
    phi [ 1 ] = 0
    for i in range ( 2 , N , 1 ) :
        phi [ i ] = i
    for p in range ( 2 , N ) :
        if ( phi [ p ] == p ) :
            phi [ p ] = p - 1
            for i in range ( 2 * p , N , p ) :
                phi [ i ] = ( phi [ i ] // p ) * ( p - 1 )
def prefix ( ) :
    for i in range ( 1 , N , 1 ) :
        pref [ i ] = pref [ i - 1 ] + phi [ i ]
def find_pairs ( n ) :
    total = ( n * ( n - 1 ) ) // 2
    ans = total - pref [ n ]
    print ( " Number ▁ of ▁ pairs ▁ from ▁ 1 ▁ to " , n , " are " , ans )
if __name__ == ' _ _ main _ _ ' :
    precompute ( )
    prefix ( )
    q = [ 5 , 7 ]
    n = len ( q )
    for i in range ( n ) :
        find_pairs ( q [ i ] )

Index/key variables: i, n, p
Iterator variables: i, p
Python program:
def maxAlternatingSum ( arr , n ) :
    max_sum = 0
    i = 0
    while i < n :
        current_max = arr [ i ]
        k = i
        while k < n and ( ( arr [ i ] > 0 and arr [ k ] > 0 ) or ( arr [ i ] < 0 and arr [ k ] < 0 ) ) :
            current_max = max ( current_max , arr [ k ] )
            k += 1
        max_sum += current_max
        i = k
    return max_sum
arr = [ 1 , 2 , 3 , 4 , - 1 , - 2 ]
n = len ( arr )
print ( maxAlternatingSum ( arr , n ) )

Index/key variables: i, k
Accumulator variables: max_sum
Python program:
def subarrayLength ( A , R , N , M ) :
    for i in range ( M ) :
        l = R [ i ] [ 0 ]
        r = R [ i ] [ 1 ] + 1
        l -= 1
        r -= 1
        A [ l ] += 1
        if ( r < N ) :
            A [ r ] -= 1
    for i in range ( 1 , N ) :
        A [ i ] += A [ i - 1 ]
    count = 0
    s = [ ]
    for i in range ( N ) :
        if ( A [ i ] not in s ) :
            count += 1
        s . append ( A [ i ] )
    repeat = [ 0 ] * ( count + 1 )
    ans = N
    counter , left , right = 0 , 0 , 0
    while ( right < N ) :
        cur_element = A [ right ]
        repeat [ cur_element ] += 1
        if ( repeat [ cur_element ] == 1 ) :
            counter += 1
        while ( counter == count ) :
            ans = min ( ans , right - left + 1 )
            cur_element = A [ left ]
            repeat [ cur_element ] -= 1
            left += 1
            if ( repeat [ cur_element ] == 0 ) :
                counter -= 1
        right += 1
    return ans
if __name__ == " _ _ main _ _ " :
    N , queries = 8 , 6
    Q = [ [ 1 , 4 ] , [ 3 , 4 ] , [ 4 , 5 ] , [ 5 , 5 ] , [ 7 , 8 ] , [ 8 , 8 ] ]
    A = [ 0 ] * N
    print ( subarrayLength ( A , Q , N , queries ) )

Index/key variables: cur_element, i, l, left, r, right
Accumulator variables: count, counter, s
Iterator variables: i
Python program:
def ModifiedSieveOfEratosthenes ( N , Expo_Prime ) :
    primes = [ True ] * N ;
    for i in range ( 2 , N ) :
        if ( primes [ i ] ) :
            no = i ;
            while ( no <= N ) :
                Expo_Prime [ no ] = True ;
                no *= i ;
            for j in range ( i * i , N , i ) :
                primes [ j ] = False ;
def Display ( arr , Expo_Prime , n ) :
    for i in range ( n ) :
        if ( Expo_Prime [ arr [ i ] ] ) :
            print ( arr [ i ] , end = " ▁ " ) ;
def FindExpoPrime ( arr , n ) :
    max = 0 ;
    for i in range ( n ) :
        if ( max < arr [ i ] ) :
            max = arr [ i ] ;
    Expo_Prime = [ False ] * ( max + 1 ) ;
    ModifiedSieveOfEratosthenes ( max + 1 , Expo_Prime ) ;
    Display ( arr , Expo_Prime , n ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 6 , 9 , 16 , 1 , 3 , 12 , 36 , 625 , 1000 ] ;
    n = len ( arr ) ;
    FindExpoPrime ( arr , n ) ;

Index/key variables: i, j, no
Iterator variables: i, j
Python program:
def nthRoot ( A , N ) :
    xPre = 7
    eps = 1e-3
    delX = 10 ** 9
    xK = 0
    while ( delX > eps ) :
        xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N
        delX = abs ( xK - xPre )
        xPre = xK
    return xK
def check ( no , k ) :
    kth_root = nthRoot ( no , k )
    num = int ( kth_root )
    if ( abs ( num - kth_root ) < 1e-4 ) :
        return True
    return False
def printExpo ( arr , n , k ) :
    for i in range ( n ) :
        if ( check ( arr [ i ] , k ) ) :
            print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    K = 6
    arr = [ 46656 , 64 , 256 , 729 , 16 , 1000 ]
    n = len ( arr )
    printExpo ( arr , n , K )

Index/key variables: i
Iterator variables: i
Python program:
def CntcontSubs ( a , n ) :
    c = 0
    d = 0
    sum = 1
    for i in range ( n ) :
        if ( a [ i ] % 2 != 0 or a [ i ] % 4 == 0 ) :
            d += 1
        sum = a [ i ]
        for j in range ( i + 1 , n ) :
            sum = sum * a [ j ]
            if ( sum % 2 != 0 or sum % 4 == 0 ) :
                c += 1
        sum = 1
    return c + d
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 4 , 2 , 9 , 8 ]
    n = len ( arr )
    print ( CntcontSubs ( arr , n ) )

Index/key variables: i, j
Accumulator variables: c, d
Iterator variables: i, j
Python program:
def CntcontSubs ( a , n ) :
    prod = 1
    vect = [ ]
    vect . append ( ( 0 , 2 ) )
    two , zero = [ ] , [ ]
    for i in range ( n ) :
        a [ i ] = a [ i ] % 4
        if ( a [ i ] < 0 ) :
            a [ i ] = a [ i ] + 4
        if ( a [ i ] == 2 ) :
            two . append ( i + 1 )
        if ( a [ i ] == 0 ) :
            zero . append ( i + 1 )
        if ( a [ i ] == 0 or a [ i ] == 2 ) :
            vect . append ( ( i + 1 , a [ i ] ) )
    vect . append ( ( n + 1 , 2 ) )
    total = ( n * ( n + 1 ) ) // 2
    if ( len ( two ) == 0 ) :
        return total
    else :
        Sum = 0
        pos1 , pos2 , pos3 = - 1 , - 1 , - 1
        sz = len ( vect )
        for i in range ( 1 , sz - 1 ) :
            if ( vect [ i ] [ 1 ] == 2 ) :
                Sum += ( ( vect [ i ] [ 0 ] - vect [ i - 1 ] [ 0 ] ) * ( vect [ i + 1 ] [ 0 ] - vect [ i ] [ 0 ] ) - 1 )
        return ( total - Sum - len ( two ) )
a = [ 5 , 4 , 2 , 9 , 8 ]
n = len ( a )
print ( CntcontSubs ( a , n ) )

Index/key variables: i
Accumulator variables: Sum, two, vect, zero
Iterator variables: i