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):
import copy
import math
import time
import statistics
import math
from decimal import Decimal
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_DOWN

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''



def main():
    start = time.time()

    n = get_int()
    #youso2 = []
    #youso5 = []
    youso = []

    ans = 0
    for i in range(0,n):
        s = input()

        if not ('.' in s):
            count2 = 0
            wk = int(s)
            for ii in range(1, 15):
                if wk % 2 == 0:
                    count2 += 1
                    wk = wk // 2
                else:
                    break

            count5 = 0
            wk = int(s)
            for ii in range(1, 6):
                if wk % 5 == 0:
                    count5 += 1
                    wk = wk // 5
                else:
                    break

            youso.append([count2, count5])
            #youso2.append(count2)
            #youso5.append(count5)

        else:
            s_i, s_d = s.split('.')

            count2 = 0
            wk = int(s_d)
            for ii in range(1, 35):
                if (wk * 2) % 10 == 0:
                    wk = wk * 2 / 10
                    count2 += 1
                else:
                    break

            #youso2.append(-len(s_d) + count2)

            count5 = 0
            wk = int(s_d)
            for ii in range(1,25):
                if (wk * 5) % 10 == 0:
                    wk = wk * 5 / 10
                    count5 += 1
                else:
                    break

            #youso5.append(-len(s_d) + count5)
            youso.append([-len(s_d) + count2, -len(s_d) + count5])

    #print(time.time() - start)
    #print(youso2)
    #print(youso5)

    ans = 0
    for i in range(0,n):
        y1 = youso[i]
        for ii in range(i+1,n):
            y2 = youso[ii]

            if (y1[0] + y2[0] >= 0) and (y1[1] + y2[1] >= 0):
                ans += 1


    print(ans)
    #print(time.time() - start)

if __name__ == '__main__':
    main()


import copy
import math
import time
import statistics
import math
from decimal import Decimal
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_DOWN

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''



def main():
    start = time.time()

    n = get_int()
    #youso2 = []
    #youso5 = []
    youso = []
    aite = [[0] * 20 for i in range(20)]

    ans = 0
    for i in range(0,n):
        s = input()
        wk = Decimal(s)
        wk = wk - wk.quantize(Decimal('0'), rounding=ROUND_DOWN)
        seisu = Decimal.is_zero(wk)

        if seisu:
            if '.' in s:
                s_i, s_d = s.split('.')
                s = s_i

            count2 = 0
            wk = int(s)
            for ii in range(0, 15):
                if wk % 2 == 0:
                    count2 += 1
                    wk = wk // 2
                else:
                    break

            count5 = 0
            wk = int(s)
            for ii in range(0, 6):
                if wk % 5 == 0:
                    count5 += 1
                    wk = wk // 5
                else:
                    break

            #youso.append([count2, count5])

        else:
            s_i, s_d = s.split('.')

            count2 = 0
            wk = int(s_i + s_d)
            for ii in range(0, 50):
                if (wk * 2) % 10 == 0:
                    wk = wk * 2 / 10
                    count2 += 1
                else:
                    break

            count5 = 0
            wk = int(s_d)
            for ii in range(0,50):
                if (wk * 5) % 10 == 0:
                    wk = wk * 5 / 10
                    count5 += 1
                else:
                    break

            count2_wk = -len(s_d) + count5
            count5 = -len(s_d) + count2
            count2 = count2_wk
            #youso.append([-len(s_d) + count5, -len(s_d) + count2])

        youso.append([count2, count5])
        for ii in range (10 - count2, 20):
            for iii in range(10 - count5, 20):
                aite[ii][iii] += 1


    #print(time.time() - start)
    #print(youso)

    
        

    ans = 0
    for i in range(0,n):
        y1 = youso[i]
        if y1[0] >= 0 and y1[1] >= 0:
            ans += aite[10 + y1[0]][10 + y1[1]] -1
        else:
            ans += aite[10 + y1[0]][10 + y1[1]]

    ans = ans /2

    print(ans)
    #print(time.time() - start)

if __name__ == '__main__':
    main()


import copy
import math
import time
import statistics
import math
from decimal import Decimal
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_DOWN

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''



def main():
    start = time.time()

    n = get_int()
    #youso2 = []
    #youso5 = []
    youso = []
    aite = [[0] * 20 for i in range(20)]

    ans = 0
    for i in range(0,n):
        s = input()
        wk = Decimal(s)
        wk = wk - wk.quantize(Decimal('0'), rounding=ROUND_DOWN)
        seisu = Decimal.is_zero(wk)

        if seisu:
            if '.' in s:
                s_i, s_d = s.split('.')
                s = s_i

            count2 = 0
            wk = int(s)
            for ii in range(0, 19):
                if wk % 2 == 0:
                    count2 += 1
                    wk = wk // 2
                else:
                    break

            count5 = 0
            wk = int(s)
            for ii in range(0, 19):
                if wk % 5 == 0:
                    count5 += 1
                    wk = wk // 5
                else:
                    break

            count5 = min(9, count5)
            count2 = min(9, count2)
            #youso.append([count2, count5])

        else:
            s_i, s_d = s.split('.')

            while s_d[-1] == '0':
                s_d = s_d[:-1]

            count2 = 0
            wk = int(s_i + s_d)
            for ii in range(0, 19):
                if (wk * 2) % 10 == 0:
                    wk = wk * 2 / 10
                    count2 += 1
                else:
                    break

            count5 = 0
            wk = int(s_i + s_d)
            for ii in range(0,19):
                if (wk * 5) % 10 == 0:
                    wk = wk * 5 / 10
                    count5 += 1
                else:
                    break

            count2_wk = -len(s_d) + count5
            count5 = min(9, -len(s_d) + count2)
            count2 = min(9, count2_wk)
            #youso.append([-len(s_d) + count5, -len(s_d) + count2])

        youso.append([count2, count5])
        aite[10 - count2][10 - count5] += 1
        #for ii in range (10 - count2, 20):
        #    for iii in range(10 - count5, 20):
        


    #print(time.time() - start)

    aite2 = [[0] * 20 for i in range(20)]
    for i in range (0,20):
        for ii in range (0, 20):
            for iii in range(i, 20):
                for iiii in range(ii, 20):
                    aite2[iii][iiii] += aite[i][ii]

    #print(time.time() - start)
    #print(youso)

    
    

    ans = 0
    for i in range(0,n):
        y1 = youso[i]
        if y1[0] >= 0 and y1[1] >= 0:
            ans += aite2[10 + y1[0]][10 + y1[1]] -1
        else:
            ans += aite2[10 + y1[0]][10 + y1[1]]

    ans = ans // 2

    print(ans)
    #print(time.time() - start)

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Runtime Error

Accepted