Problem:


Score : 300 points

Problem Statement

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.

Constraints

2 \leq N \leq 200\,000

0 < A_i < 10^4

A_i is given with at most 9 digits after the decimal.

Input

Input is given from Standard Input in the following format.

N
A_1
A_2
\vdots
A_N

Output

Print the number of pairs with integer product A_i \cdot A_j (and i < j).

Sample Input 1

5
7.5
2.4
17.000000001
17
16.000000000

Sample Output 1

3

There are 3 pairs with integer product:

7.5 \cdot 2.4 = 18

7.5 \cdot 16 = 120

17 \cdot 16 = 272

Sample Input 2

11
0.9
1
1
1.25
2.30000
5
70
0.000000001
9999.999999999
0.999999999
1.000000001

Sample Output 2

8



Sample input:
5
7.5
2.4
17.000000001
17
16.000000000


Sample output:
3

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
from decimal import *
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.readline())
def FI(): return float(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
D = defaultdict(lambda:defaultdict(int))
for j in range(n):
    a = input()
    r = len(a) - a.find(".") - 1 if "." in a else 0
    a = a.replace(".", "")
    cnt1 = -r
    cnt2 = -r
    a = int(a)
    while a % 2 == 0:
        a /= 2
        cnt1 += 1
    while a % 5 == 0:
        a /= 5
        cnt2 += 1
    D[cnt1][cnt2] += 1

ans = 0
for i in range(-20, 30):
    for k in range(-10, 15):
        for j in range(-20, 30):
            for l in range(-10, 15):
                if i + k >= 0 and j + l >= 0:
                    if i == k and j == l:
                        ans += D[i][j] * (D[k][l] - 1)
                    else:
                        ans += D[i][j] * D[k][l]

print(ans // 2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
from decimal import *
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.readline())
def FI(): return float(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
D = defaultdict(lambda:defaultdict(int))
for j in range(n):
    a = input()
    r = len(a) - a.find(".") - 1 if "." in a else 0
    a = a.replace(".", "")
    cnt1 = -r
    cnt2 = -r
    a = int(a)
    while a % 2 == 0:
        a /= 2
        cnt1 += 1
    while a % 5 == 0:
        a /= 5
        cnt2 += 1
    D[cnt1][cnt2] += 1

ans = 0
for i in range(-15, 20):
    for k in range(-15, 25):
        for j in range(-10, 12):
            for l in range(-10, 12):
                if i + k >= 0 and j + l >= 0:
                    if i == k and j == l:
                        ans += D[i][j] * (D[k][l] - 1)
                    else:
                        ans += D[i][j] * D[k][l]

print(ans // 2)

Submission status: Wrong Answer

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    m = [[0] * 20 for _ in range(20)]
    Ad = []
    for a in A:
        p = a.index('.') if a.count('.') > 0 else len(a) - 1
        l = len(a) - p - 1
        n = int(a.replace('.', '') + '0' * (9 - l))
        if n == 0:
            m[18][18] += 1
            Ad.append((18, 18))
            continue
        d2, d5 = 0, 0
        while n % 2 == 0:
            d2 += 1
            n //= 2
        while n % 5 == 0:
            d5 += 1
            n //= 5
        d2 = min(d2, 19)
        d5 = min(d5, 19)
        m[d2][d5] += 1
        Ad.append((d2, d5))
    for i in range(19, 0, -1):
        for j in range(20):
            m[i - 1][j] += m[i][j]
    for i in range(20):
        for j in range(19, 0, -1):
            m[i][j - 1] += m[i][j]
    ans = 0
    for d2, d5 in Ad:
        dd2, dd5 = 18 - d2, 18 - d5
        ans += m[dd2][dd5]
        if d2 >= dd2 and d5 >= dd5:
            ans -= 1
    print(ans // 2)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    A = [input().rstrip() for _ in range(N)]
    main(N, A)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(float, read().split())
    M = [[0] * 19 for _ in range(19)]
    #print(A)
    minus = 0
    for i, a in enumerate(A):
        if a == int(a):
            minus += 1
        a *= 10 ** 9
        a = int(a)
        
        #print(a)
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (min(f2, 18), min(f5, 18))
        M[min(f2, 18)][min(f5, 18)] += 1

        
    #print(A)
    #for m in M:
    #    print(m)
    
    for i in range(18, 0, -1):
        for j in range(18, -1, -1):
            M[i-1][j] += M[i][j]
    
    for i in range(18, -1, -1):
        for j in range(18, 0, -1):
            M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    #for m in M:
    #    print(m)


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(float, read().split())
    M = [[0] * 19 for _ in range(19)]
    print(A)
    minus = 0
    for i, a in enumerate(A):
        if a == int(a):
            minus += 1
        a *= 10 ** 9
        a = int(a)
        
        #print(a)
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (min(f2, 18), min(f5, 18))
        M[min(f2, 18)][min(f5, 18)] += 1

        
    print(A)
    #for m in M:
    #    print(m)
    
    for i in range(18, 0, -1):
        for j in range(18, -1, -1):
            M[i-1][j] += M[i][j]
    
    for i in range(18, -1, -1):
        for j in range(18, 0, -1):
            M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    #for m in M:
    #    print(m)


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect

import sys
input = sys.stdin.readline
from decimal import *
from collections import Counter


def solve(n):
    cnt = Counter()
    n_int = 0
    for _ in range(n):
        getcontext().prec = 22
        a = input().rstrip()
        da = Decimal(a)
        ia = int(da.shift(9))
        print(a,ia)
        if ia%10**9 == 0:
            n_int += 1
        pmul_2 = 0
        pmul_5 = 0
        ia2 = ia
        while ((ia2 & 1) == 0 and pmul_2 < 18): 
            ia2 = ia2 >> 1
            pmul_2 += 1
        ia5 = ia
        while 1:
            if (ia5 % 5 ==0 and pmul_5 < 18):
                pmul_5 += 1
                ia5 = ia5//5
            else:
                break
        cnt[(pmul_2,pmul_5)] += 1
    ans = 0
    #print(cnt)
    for pm2_1 in range(0,19):
        for pm2_2 in range(18-pm2_1,19):
            for pm5_1 in range(0,19):
                for pm5_2 in range(18-pm5_1,19):
                    ans += cnt[(pm2_1,pm5_1)]*cnt[(pm2_2,pm5_2)]
    ans -= n_int
    ans = ans//2
    
    print(ans)
                






def main():
    n = int(input())
    solve(n)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect

import sys
input = sys.stdin.readline
from decimal import *
from collections import Counter


def solve(n):
    cnt = Counter()
    n_int = 0
    for _ in range(n):
        getcontext().prec = 22
        a = input().rstrip()
        da = Decimal(a)
        ia = int(da.shift(9))
        print(a,ia)
        if ia%10**9 == 0:
            n_int += 1
        pmul_2 = 0
        pmul_5 = 0
        ia2 = ia
        while ((ia2 & 1) == 0 and pmul_2 < 18): 
            ia2 = ia2 >> 1
            pmul_2 += 1
        ia5 = ia
        while 1:
            if (ia5 % 5 ==0 and pmul_5 < 18):
                pmul_5 += 1
                ia5 = ia5//5
            else:
                break
        cnt[(pmul_2,pmul_5)] += 1
    ans = 0
    print(cnt)
    for pm2_1 in range(0,19):
        for pm2_2 in range(18-pm2_1,19):
            for pm5_1 in range(0,19):
                for pm5_2 in range(18-pm5_1,19):
                    ans += cnt[(pm2_1,pm5_1)]*cnt[(pm2_2,pm5_2)]
    ans -= n_int
    ans = ans//2
    
    print(ans)
                






def main():
    n = int(input())
    solve(n)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    m = [[0] * 20 for _ in range(20)]
    Ad = []
    for a in A:
        p = a.index('.') if a.count('.') > 0 else len(a) - 1
        l = len(a) - p - 1
        n = int(a.replace('.', '') + '0' * (9 - l))
        d2, d5 = 0, 0
        while n % 2 == 0:
            d2 += 1
            n //= 2
        while n % 5 == 0:
            d5 += 1
            n //= 5
        d2 = min(d2, 19)
        d5 = min(d5, 19)
        m[d2][d5] += 1
        Ad.append((d2, d5))
    for i in range(19, 0, -1):
        for j in range(20):
            m[i - 1][j] += m[i][j]
    for i in range(20):
        for j in range(19, 0, -1):
            m[i][j - 1] += m[i][j]
    ans = 0
    for d2, d5 in Ad:
        dd2, dd5 = 18 - d2, 18 - d5
        ans += m[dd2][dd5]
        if d2 >= dd2 and d5 >= dd5:
            ans -= 1
    print(ans // 2)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    A = [input().rstrip() for _ in range(N)]
    main(N, A)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(float, read().split())
    M = [[0] * 19 for _ in range(19)]
    
    minus = 0
    for i, a in enumerate(A):
        if a == int(a):
            minus += 1
        a *= 10 ** 9
        a = int(a)
        
        #print(a)
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (min(f2, 18), min(f5, 18))
        M[min(f2, 18)][min(f5, 18)] += 1

        
    #print(A)
    #for m in M:
    #    print(m)
    
    for i in range(18, 0, -1):
        for j in range(18, -1, -1):
            M[i-1][j] += M[i][j]
    
    for i in range(18, -1, -1):
        for j in range(18, 0, -1):
            M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    #for m in M:
    #    print(m)


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(float, read().split())
    M = [[0] * 19 for _ in range(19)]
    
    minus = 0
    for i, a in enumerate(A):
        if a == int(a):
            minus += 1
        a *= 10 ** 9
        a = int(a)
        
        #print(a)
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (min(f2, 18), min(f5, 18))
        M[min(f2, 18)][min(f5, 18)] += 1

        
    #print(A)
    #for m in M:
    #    print(m)
    
    for i in range(18, 0, -1):
        for j in range(18, -1, -1):
            M[i-1][j] += M[i][j]
    
    for i in range(18, -1, -1):
        for j in range(18, 0, -1):
            M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    for m in M:
        print(m)


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect

import sys
input = sys.stdin.readline
from decimal import *
from collections import Counter


def solve(n):
    cnt = Counter()
    n_int = 0
    for _ in range(n):
        getcontext().prec = 22
        a = input()
        da = Decimal(a)
        ia = int(da.shift(9))
        if ia%10**9 == 0:
            n_int += 1
        pmul_2 = 0
        pmul_5 = 0
        ia2 = ia
        while ((ia2 & 1) == 0 and pmul_2 < 18): 
            ia2 = ia2 >> 1
            pmul_2 += 1
        ia5 = ia
        while 1:
            if (ia5 % 5 ==0 and pmul_5 < 18):
                pmul_5 += 1
                ia5 = ia5//5
            else:
                break
        cnt[(pmul_2,pmul_5)] += 1
    ans = 0
    #print(cnt)
    for pm2_1 in range(0,19):
        for pm2_2 in range(18-pm2_1,19):
            for pm5_1 in range(1,19):
                for pm5_2 in range(18-pm5_1,19):
                    ans += cnt[(pm2_1,pm5_1)]*cnt[(pm2_2,pm5_2)]
    ans -= n_int
    ans = ans//2

    print(ans)
                






def main():
    n = int(input())
    solve(n)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    from collections import defaultdict
    from fractions import Fraction
    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        x = Fraction(input())
        cnt0, cnt5, cnt2 = 0, 0, 0
        for j in range(5):
            if x % 1 == 0:
                break
            else:
                x *= 10
                cnt0 += 1
        if cnt0 == 5:
            continue
        for j in range(4):
            if x % 5 != 0:
                break
            else:
                x //= 5
                cnt5 += 1
        for j in range(4):
            if x % 2 != 0:
                break
            else:
                x //= 2
                cnt2 += 1
        d[(cnt0, cnt2, cnt5)] += 1
    #print(d)
    lis = list(d)
    #print(lis)
    ans_0 = 0
    ans_f = 0
    for i, (a, b, c) in enumerate(lis):
        k = d[(a, b, c)]
        l = 0
        for x, y, z in lis:
            if a == x == 0 and b == y and c == z:
                ans_0 += k * (k - 1)
            elif b + y >= a + x and c + z >= a + x:
                l = d[(x, y, z)]
                ans_f += k * l
    print((ans_0 + ans_f) // 2)
    return
solve()

Submission status: Wrong Answer

Solution code:
def solve():
    from collections import defaultdict
    from fractions import Fraction
    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        x = Fraction(input())
        cnt0, cnt5, cnt2 = 0, 0, 0
        for j in range(5):
            if x % 1 == 0:
                break
            else:
                x *= 10
                cnt0 += 1
        if cnt0 == 5:
            continue
        for j in range(4):
            if x % 5 != 0:
                break
            else:
                x //= 5
                cnt5 += 1
        for j in range(4):
            if x % 2 != 0:
                break
            else:
                x //= 2
                cnt2 += 1
        d[(cnt0, cnt2, cnt5)] += 1
    print(d)
    lis = list(d)
    print(lis)
    ans_0 = 0
    ans_f = 0
    for i, (a, b, c) in enumerate(lis):
        k = d[(a, b, c)]
        l = 0
        for x, y, z in lis:
            if a == x == 0 and b == y and c == z:
                ans_0 += k * (k - 1)
            elif b + y >= a + x and c + z >= a + x:
                l = d[(x, y, z)]
                ans_f += k * l
    print((ans_0 + ans_f) // 2)

    return
solve()

Submission status: Wrong Answer

Solution code:
import copy
from decimal import Decimal
n = int(input())
l = []
for i in range(n):
    a = str(input())
    if "." not in a:
        l.append(Decimal(a))
    else:
        dot = a.index(".")
        if len(a)-dot-1 <= 4:
            l.append(Decimal(a))
        else:
            flag = 1
            for j in range(dot+5,len(a)):
                if a[j] != "0":
                    flag = 0
            if flag: l.append(Decimal(a)) 
n = len(l)
a = [int(l[i]*10**4) for i in range(n)]
memo = [[0,0] for _ in range(n)]
for i in range(n):
    t = a[i]
    while t%2 == 0 and t != 0:
        t //= 2
        memo[i][0] += 1
    while t%5 == 0 and t != 0:
        t //= 5
        memo[i][1] += 1
mem2 = [[0]*9 for _ in range(9)]
p = 0
for i in range(n):
    if memo[i][0] >= 8 and memo[i][1] >= 8:
        p += 1
    else:
        if memo[i][0] > 8:
            memo[i][0] = 8
        if memo[i][1] > 8:
            memo[i][1] = 8
        mem2[memo[i][0]][memo[i][1]] += 1
mems = copy.deepcopy(mem2)


for i in range(8,-1,-1):
    for j in range(7,-1,-1):
        mems[i][j] += mems[i][j+1]
for i in range(7,-1,-1):
    for j in range(8,-1,-1):
        mems[i][j] += mems[i+1][j]

s = 0
for i in range(9):
    for j in range(9):
        
        if i >= 4 and j >= 4:
            s += mem2[i][j] * (mems[8-i][8-j]-1)
        else:
            s += mem2[i][j] * mems[8-i][8-j]
s = s//2
s += p*(p-1)//2+p*(n-p)
print(s)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(float, read().split())
    M = [[0] * 19 for _ in range(19)]
    
    minus = 0
    for i, a in enumerate(A):
        a *= 10 ** 9
        a = int(a)
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (min(f2, 18), min(f5, 18))
        M[min(f2, 18)][min(f5, 18)] += 1
        if f2 > 8 and f5 > 8:
            minus += 1
        
    
    #for m in M:
    #    print(m)
    
    for i in range(18, 0, -1):
        for j in range(18, -1, -1):
            M[i-1][j] += M[i][j]
    
    for i in range(18, -1, -1):
        for j in range(18, 0, -1):
            M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    #for m in M:
    #    print(m)


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# A - Integer Product 
n = int(input())
a = [input() for _ in range(n)]

# bi=ai*(10**9)とすると、(aiは小数第9位までの小数だからbiは整数)
# ai*ajが整数<=>bi*bj/(10**18)が整数<=>bi*bjが素因数に2を18個、5を18個持つ。
# p2[i]:biを素因数分解したときの2の数。
# p5[i]:biを素因数分解したときの5の数。
# c25[i][j]:bi...bnのうち、素因数に2をi個以上、5をj個以上持つbiの数。
# biに対して、ペアになれるのはc25[18-p2[i]][18-p5[i]]個。
# ただし、自分自身は含めないのでbiが素因数として2を9個以上、5を9個以上もつときは―1する。
# また、(bi,bj)と(bj,bi)を重複して数えてしまうので、最後に//2する。

p2 = [0 for _ in range(n)]
p5 = [0 for _ in range(n)]

for i in range(n):
  # Decimalを使ったらTLEしてしまったので、文字列操作でbiを計算する。
  if '.' in a[i]:
    bi = int(a[i].replace('.','')+'0'*(9-(len(a[i])-a[i].index('.')-1)))
  else:
    bi = int(a[i])*(10**9)
  c = 0
  while(bi%2 == 0):
    c += 1
    bi //= 2
  p2[i] = c
  c = 0
  while(bi%5 == 0):
    c += 1
    bi //= 5
  p5[i] = c

c25 = [[0 for _ in range(50)] for _ in range(50)]
for i in range(n):
  c25[p2[i]][p5[i]] += 1
for i in range(18,-1,-1):
  for j in range(18,-1,-1):
    c25[i][j] += c25[i+1][j]+c25[i][j+1]-c25[i+1][j+1]

ans = 0
for i in range(n):
  ans += c25[max(18-p2[i],0)][max(18-p5[i],0)]
  if p2[i] >= 9 and p5[i] >= 9:
    ans -= 1
print(ans//2)

Submission status: Wrong Answer

Solution code:
# A - Integer Product 
n = int(input())
a = [float(input()) for _ in range(n)]

# bi=ai*(10**9)とすると、(aiは小数第9位までの小数だからbiは整数)
# ai*ajが整数<=>bi*bj/(10**18)が整数<=>bi*bjが素因数に2を18個、5を18個持つ。
# p2[i]:biを素因数分解したときの2の数。
# p5[i]:biを素因数分解したときの5の数。
# c25[i][j]:bi...bnのうち、素因数に2をi個以上、5をj個以上持つbiの数。
# biに対して、ペアになれるのはc25[18-p2[i]][18-p5[i]]個。
# ただし、自分自身は含めないのでbiが素因数として2を9個以上、5を9個以上もつときは―1する。
# また、(bi,bj)と(bj,bi)を重複して数えてしまうので、最後に//2する。

p2 = [0 for _ in range(n)]
p5 = [0 for _ in range(n)]

for i in range(n):
  bi = a[i]*(10**9)
  c = 0
  while(bi%2 == 0 and c < 18):
    c += 1
    bi //= 2
  p2[i] = c
  c = 0
  while(bi%5 == 0 and c < 18):
    c += 1
    bi //= 5
  p5[i] = c

c25 = [[0 for _ in range(20)] for _ in range(20)]
for i in range(n):
  c25[p2[i]][p5[i]] += 1
for i in range(18,-1,-1):
  for j in range(18,-1,-1):
    c25[i][j] += c25[i+1][j]+c25[i][j+1]-c25[i+1][j+1]

ans = 0
for i in range(n):
  ans += c25[18-p2[i]][18-p5[i]]
  if p2[i] >= 9 and p5[i] >= 9:
    ans -= 1
print(ans//2)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
count = 0
A =[]
for i in range(N):
    a = float(input())
    A.append(a)



for pair in itertools.combinations(A,2):
    b = pair[0] *(10**9)* pair[1]*(10**9) /10**18  
    
    if  b.is_integer() == True:
        count += 1
        #print(b, pair)
    
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

nums = [float(input()) for _ in range(N)]

two_fives = []


for i, num in enumerate(nums):
    int_converted = int(num * (10**9))
    
    two_div_count = 0
    while int_converted % 2 == 0:
        two_div_count += 1
        int_converted //= 2
    
    five_div_count = 0
    while int_converted % 5 == 0:
        five_div_count += 1
        int_converted //= 5

    two_fives.append((two_div_count,five_div_count))


ok_count = 0
for i in range(N):
    for j in range(i+1,N):
        two_sum = two_fives[i][0] + two_fives[j][0]
        five_sum = two_fives[i][1] + two_fives[j][1]
        if two_sum >= 18 and five_sum >= 18:
            ok_count += 1

print(ok_count)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

alist = []
for i in range(n):
    alist.append(int(round(float(input())*10**9)))

def two_five_power(n):
    a = 0
    b = 0
    while n % 2 == 0:
        n /=2
        a += 1
    while n % 5 == 0:
        n /= 5
        b += 1
    return (a,b)

ab_dict = dict()
for i in range(n):
    ab = two_five_power(alist[i])
    if ab in ab_dict:  
        ab_dict[ab] += 1
    else:
        ab_dict[ab] = 1

prev = 0
count = 0
for one in ab_dict:
    for two in ab_dict:
        if one[0] + two[0] >= 18 and one[1] + two[1] >= 18:    
            if one < two:
                count += ab_dict[one] * ab_dict[two]
            else: 
                count += ab_dict[one] * (ab_dict[two]-1) // 2

print(count)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

alist = []
for i in range(n):
    alist.append(round(float(input())*10**9))

def two_five_power(n):
    a = 0
    b = 0
    while n % 2 == 0:
        n /=2
        a += 1
    while n % 5 == 0:
        n /= 5
        b += 1
    return (a,b)

ab_dict = dict()
for i in range(n):
    ab = two_five_power(alist[i])
    if ab in ab_dict:  
        ab_dict[ab] += 1
    else:
        ab_dict[ab] = 1

prev = 0
count = 0
for one in ab_dict:
    for two in ab_dict:
        if one[0] + two[0] >= 18 and one[1] + two[1] >= 18:    
            if one < two:
                count += ab_dict[one] * ab_dict[two]
            else: 
                count += ab_dict[one] * (ab_dict[two]-1) / 2

print(int(count))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

alist = []
for i in range(n):
    alist.append(round(float(input())*10**9))

def two_five_power(n):
    a = 0
    b = 0
    while n % 2 == 0:
        n /=2
        a += 1
    while n % 5 == 0:
        n /= 5
        b += 1
    return (a,b)

ab_dict = dict()
for i in range(n):
    ab = two_five_power(alist[i])
    if ab in ab_dict:  
        ab_dict[ab] += 1
    else:
        ab_dict[ab] = 1

prev = 0
count = 0
for one in ab_dict:
    for two in ab_dict:
        if one[0] + two[0] >= 18 and one[1] + two[1] >= 18:    
            if one < two:
                count += ab_dict[one] * ab_dict[two]
            else: 
                count += ab_dict[one] * (ab_dict[two]-1) // 2

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = 10 ** 9
for _ in range(N):
	A.append(float(input())* B)
S = set()
ans = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		ai, aj = A[i], A[j]
		s = (ai, aj) if ai >= aj else (aj, ai)
		if s not in S:
			x = ai * aj
			if x % (B ** 2) == 0:
				S.add(s)
				ans += 1
		else:
			ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def count5(n):
    count = 0
    while n%5 == 0:
        count += 1
        n //= 5
    return count

def count2(n):
    count = 0
    while n%2 == 0:
        count += 1
        n //= 2
    return count

N = I()
A = []
for i in range(N):
    A.append(int(10**9*float(input())))

counter = [[0]*30 for _ in range(50)]
for i in range(N):
    c2 = count2(A[i])
    c5 = count5(A[i])
    counter[c2][c5] += 1

same = 0
diff = 0
for i in range(50):
    for j in range(30):
        if counter[i][j]:
            for p in range(18-i,50):
                for q in range(18-j,30):
                    if i != p or j != q:
                        diff += counter[i][j]*counter[p][q]
                    else:
                        same += counter[i][j]*(counter[p][q]-1)//2

print(diff//2+same)

Submission status: Wrong Answer

Solution code:
""" A
    https://atcoder.jp/contests/agc047/tasks/agc047_a
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return [lambda _: readIntegerSet(m) for _ in range(0, n)]

def main(N, A):
    count = 0

    p9 = pow(10, 9)
    p18 = pow(10, 18)

    for i in range(0, _N):
        for j in range(i+1, _N):
            print(A[i], A[j], A[i] * A[j])
            Ai_0 = int(A[i])
            Ai_1 = int(A[i] * p9) % p9
            Aj_0 = int(A[j])
            Aj_1 = int(A[j] * p9) % p9

            C = (
                (Ai_0 * Aj_1) % p9 * p9 \
                + (Aj_0 * Ai_1) % p9 * p9 \
                + (Ai_1 * Aj_1) % p18
            ) % p18

            if C == 0:
                count += 1

    return count

if __name__ == "__main__":
    _N = readInteger()
    _A = [float(readString()) for _ in range(0, _N)]

    print(main(_N, _A))