Problem: You are given N real values A_1, A_2, \ldots, A_N. Compute the number of pairs of indices (i, j) such that i < j and the product A_i \cdot A_j is integer.

Submission attempts (in order):
def prog(x):
    n = len(x)
    y = [int(i * 10**9) for i in x]
    #y

    def count25(n):
        two = five = 0
        while n % 2 == 0:
            two += 1
            n //= 2
        while n % 5 == 0:
            five += 1
            n //= 5
        return two, five

    two = [0] * n
    five = [0] * n
    for i in range(n):
        two[i], five[i] = count25(y[i])
    count = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            #if min(two[i] + two[j], five[i] + five[j]) >= 18:
            if two[i] + two[j] >= 18 and five[i] + five[j] >= 18:
                #print(min(two1,two2) + min(five1, five2), two1, two2, five1, five2)
                #print(y[i] * y[j], (y[i] * y[j]) / 10**18)
                #print(y[i] / 10**9, y[j] / 10**9)
                #print('=================')
                count += 1
    print(count)

n = int(input())
x = list(map(int, input().split()))
prog(x)


def prog(x):
    n = len(x)
    y = [int(i * 10**9) for i in x]
    #y

    def count25(s): # count25(0)
        if s.find('.') == -1:
            s += '.'
        s = s.rstrip('0')
        decimal_point = s.find('.')
        int_part = s[:decimal_point]
        float_part = s[decimal_point+1:]
        float_part += '0' * (9 - len(float_part))
        n = int(int_part + float_part)
        if n == 0:
            return (0, 0)
        two = five = 0
        while n % 2 == 0:
            two += 1
            n //= 2
        while n % 5 == 0:
            five += 1
            n //= 5
        return (two, five)

    two = [0] * n
    five = [0] * n
    for i in range(n):
        two[i], five[i] = count25(y[i])
    count = 0
    for i in range(n - 1):
        two_i = 18 - two[i]
        five_i = 18 - five[i]
        for j in range(i + 1, n):
            #if min(two[i] + two[j], five[i] + five[j]) >= 18:
            if two[j] >= two_i and five[j] >= five_i:
                #print(min(two1,two2) + min(five1, five2), two1, two2, five1, five2)
                #print(y[i] * y[j], (y[i] * y[j]) / 10**18)
                #print(y[i] / 10**9, y[j] / 10**9)
                #print('=================')
                count += 1
    print(count)

n = int(input())
x = [0] * n
x = [input() for i in range(n)]
prog(x)


def prog(x):
    n = len(x)

    def count25(s): # count25(0)
        if s.find('.') == -1:
            s += '.'
        s = s.rstrip('0')
        decimal_point = s.find('.')
        int_part = s[:decimal_point]
        float_part = s[decimal_point+1:]
        float_part += '0' * (9 - len(float_part))
        n = int(int_part + float_part)
        if n == 0:
            return (0, 0)
        two = five = 0
        while n % 2 == 0:
            two += 1
            n //= 2
        while n % 5 == 0:
            five += 1
            n //= 5
        return (two, five)

    d = {}
    for a in x:
        t = count25(a)
        d.setdefault(t, 0)
        d[t] += 1
    two_five = list(d.keys())
    count = 0
    for i in range(len(two_five)): 
        two, five = two_five[i]
        cnt = d[two_five[i]]
        if two >= 9 and five >= 9:
            count += cnt * (cnt -1) // 2
        for j in range(i + 1, len(two_five)):
            two2, five2 = two_five[j]
            if two + two2 >= 18 and five + five2 >= 18:
                count += cnt * d[two_five[j]]
    print(count)

n = int(input())
x = [input() for i in range(n)]
prog(x)


Verdicts: Runtime Error

Runtime Error

Accepted