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:
N=int(input())
A=[]
PRECISION_DIGITS=9
cnt={}


for n in range(N):
	tmpA = float(input())
	tmpA = tmpA*10**PRECISION_DIGITS
	#print(tmpA)

	five = 0
	two = 0
	while (tmpA % 2) == 0:
		two += 1
		tmpA /= 2
	while (tmpA % 5) == 0:
		five += 1
		tmpA /= 5

	# (10**9) -> (two,five)=(9,9)
	#two -= PRECISION_DIGITS
	#five -= PRECISION_DIGITS

	if (two,five) in cnt:
		cnt[(two,five)]+=1
	else:
		cnt[(two,five)]=1

# print(cnt)
ans = 0
for t1, cnt1 in cnt.items():
	for t2, cnt2 in cnt.items():
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if PRECISION_DIGITS*2 <= t1[0]+t2[0] and PRECISION_DIGITS*2 <= t1[1]+t2[1]:
			if t1 < t2:
				ans += cnt1*cnt2
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int((cnt1*(cnt2-1))/2)


print(ans)

Submission status: Wrong Answer

Solution code:
#AGC047-A Integer Product
"""
小数または整数が与えられるので、その積が整数となるペアの個数を求めよ。

まず入力に10**9をかけることで、
問題を「その積が10**18の倍数となるペアの個数を求めよ」
とする。
その場合、とりあえず10**18を素因数分解すると2**18と5**18なので、
片方が因数分解済みであるとした時に、
dp[i][j] : 2**iかつ5**jの個数
として、もう片方を2**aかつ5**bであると考えた時に、
2**(i+a)>=18かつ5**(j+b)>=18となるならば、それは条件を満たす
と考えられる。

よってこの個数を数えることで問題が解けた。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1  = [] 
for i in range(n):
    lst1.append(int(float(readline())*(10**9)))

dp = [[0]*50 for _ in range(50)]

ans = 0

for i in range(n):
    res = lst1[i]
    t,f = 0,0
    while True:
        if res%2==0:
            res //= 2
            t += 1
        else:
            break
    while True:
        if res%5==0:
            res //= 5
            f += 1
        else:
            break
    
    #i+t>=18かつj+f>=18であるような場所からカウント
    for i in range(50):
        if i + t < 18:
            continue
        for j in range(50):
            if j+f >= 18:
                ans += dp[i][j]
    
    dp[t][f] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
PRECISION_DIGITS=9
cnt={}


for n in range(N):
	tmpA = float(input())
	tmpA = tmpA*10**PRECISION_DIGITS
	#print(tmpA)

	five = 0
	two = 0
	while (tmpA % 2) == 0:
		two += 1
		tmpA /= 2
	while (tmpA % 5) == 0:
		five += 1
		tmpA /= 5

	# (10**9) -> (two,five)=(9,9)
	two -= PRECISION_DIGITS
	five -= PRECISION_DIGITS

	if (two,five) in cnt:
		cnt[(two,five)]+=1
	else:
		cnt[(two,five)]=1

# print(cnt)
ans = 0
for t1, cnt1 in cnt.items():
	for t2, cnt2 in cnt.items():
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if 0 <= t1[0]+t2[0] and 0 <= t1[1]+t2[1]:
			if t1 < t2:
				ans += cnt1*cnt2
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int((cnt1*(cnt2-1))/2)


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
PRECISION_DIGITS=9
cnt={}


for n in range(N):
	tmpA = float(input())
	tmpA = tmpA*10**PRECISION_DIGITS
	#print(tmpA)

	five = 0
	two = 0
	while (tmpA % 2) == 0:
		two += 1
		tmpA /= 2
	while (tmpA % 5) == 0:
		five += 1
		tmpA /= 5

	# (10**9) -> (two,five)=(9,9)
	two -= PRECISION_DIGITS
	five -= PRECISION_DIGITS

	if (two,five) in cnt:
		cnt[(two,five)]+=1
	else:
		cnt[(two,five)]=1

# print(cnt)
ans = 0
for t1, cnt1 in cnt.items():
	for t2, cnt2 in cnt.items():
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if 0 <= t1[0]+t2[0] and 0 <= t1[1]+t2[1]:
			if t1 < t2:
				ans += cnt1*cnt2
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int((cnt1*(cnt2-1))//2)


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
PRECISION_DIGITS=9
cnt={}


for n in range(N):
	tmpA = float(input())
	tmpA = tmpA*10**PRECISION_DIGITS
	#print(tmpA)

	five = 0
	two = 0
	while (tmpA % 5) == 0:
		five += 1
		tmpA /= 5
	while (tmpA % 2) == 0:
		two += 1
		tmpA /= 2

	# (10**9) -> (two,five)=(9,9)
	two -= PRECISION_DIGITS
	five -= PRECISION_DIGITS

	if (two,five) in cnt:
		cnt[(two,five)]+=1
	else:
		cnt[(two,five)]=1

# print(cnt)
ans = 0
for t1, cnt1 in cnt.items():
	for t2, cnt2 in cnt.items():
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if 0 <= t1[0]+t2[0] and 0 <= t1[1]+t2[1]:
			if t1 < t2:
				ans += cnt1*cnt2
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int((cnt1*(cnt2-1))//2)


print(ans)

Submission status: Wrong Answer

Solution code:
import math
K=10**9
N=int(input())
x = [int(float(input())*K) for i in range(N)]

Y2=[0]*N
Y5=[0]*N

for i in range(N):
  Ya=x[i]
  while(Ya%2==0):
    Ya /= 2
    Y2[i] +=1
  while(Ya%5==0):
    Ya /= 5
    Y5[i] +=1


count=0
for i in range(N):
  for j in range(i+1,N):
    if( Y2[i]+Y2[j]>=18 and Y5[i]+Y5[j]>=18):
      count +=1

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
PRECISION_DIGITS=9
cnt={}


for n in range(N):
	tmpA = float(input())
	tmpA = int(tmpA*10**PRECISION_DIGITS)
	#print(tmpA)

	five = 0
	two = 0
	while (tmpA % 5) == 0:
		five += 1
		tmpA //= 5
	while (tmpA % 2) == 0:
		two += 1
		tmpA //= 2

	# (10**9) -> (two,five)=(9,9)
	two -= PRECISION_DIGITS
	five -= PRECISION_DIGITS

	if (two,five) in cnt:
		cnt[(two,five)]+=1
	else:
		cnt[(two,five)]=1

# print(cnt)
ans = 0
for t1, cnt1 in cnt.items():
	for t2, cnt2 in cnt.items():
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if 0 <= t1[0]+t2[0] and 0 <= t1[1]+t2[1]:
			if t1 < t2:
				ans += cnt1*cnt2
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int((cnt1*(cnt2-1))//2)


print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
A=[]
PRECISION_DIGITS=9
NO_ENTRY = 0
cnt=np.full((PRECISION_DIGITS*2+1,PRECISION_DIGITS*2+1),NO_ENTRY,int)
# cnt=np.zeros((PRECISION_DIGITS*2,PRECISION_DIGITS*2),int)

# print(cnt)

for n in range(N):
	tmpA = float(input())
	tmpA = int(tmpA*10**PRECISION_DIGITS)
	#print(tmpA)

	five = 0
	two = 0
	# (10**9) -> (two,five)=(9,9)
	# min = 10**-9, ignore < 10**9 ???
	while (tmpA % 5) == 0 and five < PRECISION_DIGITS*2:
		five += 1
		tmpA //= 5
	while (tmpA % 2) == 0 and two < PRECISION_DIGITS*2:
		two += 1
		tmpA //= 2

	if cnt[two][five] == 0:
		cnt[two][five]=1
	else:
		cnt[two][five]+=1

# print(cnt)
ans = 0

for x1 in range(PRECISION_DIGITS*2):
	for y1 in range(PRECISION_DIGITS*2):
		if cnt[x1][y1] == NO_ENTRY:
			continue

		for x2 in range(PRECISION_DIGITS*2):
			for y2 in range(PRECISION_DIGITS*2):
				if cnt[x2][y2] == NO_ENTRY:
					continue
				# 2**a(a>=0) and 5**b(b>=0) => integer
				if 0 <= x1+x2 - PRECISION_DIGITS*2 and 0 <= y1+y2 -PRECISION_DIGITS*2:
					if x1 == x2 and y1 == y2:
						# same entry
						# Total number of combinations choose 2 items
						# nC2 = n*(n-1)/2
						ans += int((cnt[x1][y1]*(cnt[x2][y2]-1))//2)
					else:
						ans += cnt[x1][y1]*cnt[x2][y2]

		# count up completed entry
		cnt[x1][y1] = NO_ENTRY

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = sys.stdin.readline
N = int(input())
A = [input() for i in range(N)]

C = collections.defaultdict(int)
for i, x in enumerate(A):
    idx = 0
    x = x[:-1]
    if '.' in x:
        idx = x[::-1].index('.')
        x = x.replace('.', '')
    x = int(x)
    count2 = -idx
    count5 = -idx
    print(x, idx)
    while(x % 2 == 0):
        x = x // 2
        count2 += 1

    while(x % 5 == 0):
        x = x // 5
        count5 += 1
    C[(count2, count5)] += 1
ans = 0
for a, b in C:
    for a2, b2 in C:
        if a+a2 >= 0 and b+b2 >= 0:
            if a == a2 and b == b2:
                ans += C[(a, b)]*(C[(a, b)]-1)
            else:
                ans += C[(a, b)]*C[(a2, b2)]
print(ans//2)

Submission status: Wrong Answer

Solution code:
import collections

def solve(A):
  N = len(A)
  
  ans = 0
  counts = collections.Counter()
  for i in range(1, N):
    y = A[i]
    for j in range(i):
      res = A[j] * y
      if int(res) == res:
        ans += 1
        
  return ans


A = []
N = int(input())
for _ in range(N):
  A.append(float(input().rstrip()))
  
print(solve(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
C2 = [0] * N
C5 = [0] * N
for i in range(N):
    s = str(input())
    A.append(s)
    ok = False
    dot_idx = -1
    l = len(A[-1])
    for j in range(l):
        if A[-1][j] == '.':
            ok = True
            dot_idx = j
    if dot_idx == -1:
        A[-1] += ".000000000"
    else:
        while len(A[-1]) < 10+dot_idx:
            A[-1] += "0"
    tmp = ""
    for j in range(len(A[i])):
        if A[i][j] == '.':continue
        tmp += A[i][j]
    B.append(int(tmp))
    tmp = B[i]
    tmp2 = B[i]
    while tmp > 0:
        if tmp % 2 == 0:
            tmp //= 2
            C2[i] += 1
        else:
            break
    while tmp2 > 0:
        if tmp % 5 == 0:
            tmp //= 5
            C5[i] += 1
        else:
            break

Cc = [[] for _ in range(19)]
for i in range(N):
    Cc[min(18, C2[i])].append(C5[i])

for i in range(19):
    Cc[i].sort()

ans = 0
for i in range(N):
    # 2がC2[i]個 -> 相手は最低18-C2[i]かつ、18 - C5[i]以上の個数
    M = 18 - C5[i]
    for j in range(max(0,18-C2[i]), 19):
        ok = -1
        ng = len(Cc[j])
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if Cc[j][mid] >= M:
                ok = mid
            else: ng = mid
        ans += ok+1

for i in range(N):
    if C2[i] >= 9 and C5[i] >= 9:
        ans -=1

print(ans//2)

Submission status: Wrong Answer

Solution code:
#mult 10**9 
from decimal import Decimal
from math import gcd
from collections import Counter
n=int(input())
a=[int(Decimal(input())*10**9) for _ in range(n)]

tf = []

for i in range(n):
    t=0;f=0;
    while a[i]%2==0:
        t+=1
        a[i]//=2
    while a[i]%5==0:
        f+=1
        a[i]//=5
    tf.append((t-9,f-9))

ctf = Counter(tf)
ans=0
for t,f in ctf:
    for t2,f2 in ctf:
        if t+t2>=0 and f+f2>=0:
            if t!=t2 or f!=f2:
                ans+= ctf[(t,f)]*ctf[(t2,f2)]
            else:
                ans+= ctf[(t,f)]*(ctf[(t,f)]-1)
print(ans)

Submission status: Wrong Answer

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

dat=[[0]*19 for _ in range(19)]  
rui=[[0]*19 for _ in range(19)]

B=[]

for i in range(N):
  dev2,dev5=0,0
  while A[i]%2==0 and dev2<18:
    dev2+=1
    A[i]//=2
  while A[i]%5==0 and dev5<18:
    dev5+=1
    A[i]//=5
  dat[dev2][dev5]+=1
  B.append([dev2,dev5])
  
for i in range(19):
  for j in range(19):
    for k in range(i+1):
      for l in range(j+1):
        rui[k][l]+=dat[i][j]
  
ans=0
for i in range(N):
  dev2,dev5=B[i]
  t_dev2,t_dev5=18-dev2,18-dev5
  if dev2>=t_dev2 and dev5>=t_dev5:
    ans-=1
  ans+=rui[t_dev2][t_dev5]

print(ans//2)

Submission status: Wrong Answer

Solution code:
def count(f):
    two_cnt = 0
    five_cnt = 0
    while f.is_integer() is False:
        f *= 10
        two_cnt -= 1
        five_cnt -= 1

    while f % 2 == 0:
        two_cnt += 1
        f //= 2

    while f % 5 == 0:
        five_cnt += 1
        f //= 5

    return (two_cnt, five_cnt)


n = int(input())

table = {}

for _ in range(n):

    f = float(input())
    cnt = count(f)
    if cnt not in table:
        table[cnt] = 1
    else:
        table[cnt] += 1


ans = 0

table_list = list(table.keys())

for i in range(len(table_list)):
    two1, five1 = table_list[i]
    val1 = table[table_list[i]]

    if two1 >= 0 and five1 >= 0:
        ans += val1 * (val1 - 1) // 2

    for j in range(i + 1, len(table_list)):
        two2, five2 = table_list[j]
        val2 = table[table_list[j]]
        if two1 + two2 >= 0 and five1 + five2 >= 0:
            ans += val1 * val2

print(ans)

Submission status: Wrong Answer

Solution code:
def count(f):
    two_cnt = 0
    five_cnt = 0
    while f.is_integer() is False:
        f *= 10
        two_cnt -= 1
        five_cnt -= 1

    while f % 2 == 0:
        two_cnt += 1
        f //= 2

    while f % 5 == 0:
        five_cnt += 1
        f //= 5

    return (two_cnt, five_cnt)


n = int(input())

table = {}

for _ in range(n):

    f = float(input())
    cnt = count(f)
    if cnt not in table:
        table[cnt] = 1
    else:
        table[cnt] += 1


ans = 0

table_list = list(table.keys())
table_list.sort()

for i in range(len(table_list)):
    two1, five1 = table_list[i]
    val1 = table[table_list[i]]

    if two1 >= 0 and five1 >= 0:
        ans += val1 * (val1 - 1) // 2

    for j in range(i + 1, len(table_list)):
        two2, five2 = table_list[j]
        val2 = table[table_list[j]]
        if two1 + two2 >= 0 and five1 + five2 >= 0:
            ans += val1 * val2

print(ans)

Submission status: Wrong Answer

Solution code:
c=eval('[0]*50,'*50)
r=0
for a in[*open(0)][1:]:
 a=int(float(a)*1e9);x=y=0
 while a%2<1:a//=2;x+=1
 while a%5<1:a//=5;y+=1
 r+=sum(sum(d[max(0,18-y):])for d in c[max(0,18-x):]);c[x][y]+=1
print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
deg = [[0] * 19 for _ in range(19)]
fac = []

for _ in range(n):
    a = int(float(input()) * 1000000000)
    d2, d5 = 0, 0
    while a % 2 == 0:
        d2 += 1
        a //= 2
    while a % 5 == 0:
        d5 += 1
        a //= 5
    d2 = min(d2, 18)
    d5 = min(d5, 18)
    deg[d2][d5] += 1
    fac.append((d2, d5))

count = 0
for d2, d5 in fac:
    for i in range(18 - d2, 19):
        for j in range(18 - d5, 19):
            count += deg[i][j]
    if d2 >= 18 - d2 and d5 >= 18 - d5:
        count -= 1
print(count // 2)

Submission status: Wrong Answer

Solution code:
n = int(input())

def factorize(n):
    factor = []
    if n % 2 == 0:
        f = [2, 1]
        n //= 2
        while n % 2 == 0:
            n //= 2
            f[1] += 1
        factor.append(f)

    k = 3
    while k * k <= n:
        if n % k == 0:
            f = [k, 1]
            n //= k
            while n % k == 0:
                n //= k
                f[1] += 1
            factor.append(f)
        k += 2
    if n != 1:
        factor.append([n, 1])
    return factor

deg = [[0] * 9 for _ in range(9)]
fac = []

for _ in range(n):
    a = int(float(input()) * 1000000000)
    if a % 100000:
        continue
    a //= 100000
    d2, d5 = 0, 0
    while a % 2 == 0:
        d2 += 1
        a //= 2
    while a % 5 == 0:
        d5 += 1
        a //= 5
    d2 = min(d2, 8)
    d5 = min(d5, 8)
    deg[d2][d5] += 1
    fac.append((d2, d5))

count = 0
for d2, d5 in fac:
    for i in range(8 - d2, 9):
        for j in range(8 - d5, 9):
            count += deg[i][j]
    if d2 >= 8 - d2 and d5 >= 8 - d5:
        count -= 1
print(count // 2)

Submission status: Wrong Answer

Solution code:
def count(f):
    two_cnt = 0
    five_cnt = 0
    while f.is_integer() is False:
        f *= 10
        two_cnt -= 1
        five_cnt -= 1

    while f % 2 == 0:
        two_cnt += 1
        f //= 2

    while f % 5 == 0:
        five_cnt += 1
        f //= 5

    return (two_cnt, five_cnt)


n = int(input())

table = {}

for _ in range(n):

    f = float(input())
    cnt = count(f)
    if cnt not in table:
        table[cnt] = 1
    else:
        table[cnt] += 1


pos_cnt = 0
for key, val in table.items():
    two, five = key
    if two >= 0 and five >= 0:
        pos_cnt += val

ans = pos_cnt * (pos_cnt - 1) // 2

table_list = list(table.keys())
table_list.sort()

for i in range(len(table_list)):
    two1, five1 = table_list[i]
    val1 = table[(two1, five1)]
    if two1 < 0 or five1 < 0:
        for j in range(i + 1, len(table_list)):
            two2, five2 = table_list[j]
            val2 = table[(two2, five2)]
            if two1 + two2 >= 0 and five1 + five2 >= 0:
                ans += val1 * val2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

def factorize(n):
    factor = []
    if n % 2 == 0:
        f = [2, 1]
        n //= 2
        while n % 2 == 0:
            n //= 2
            f[1] += 1
        factor.append(f)

    k = 3
    while k * k <= n:
        if n % k == 0:
            f = [k, 1]
            n //= k
            while n % k == 0:
                n //= k
                f[1] += 1
            factor.append(f)
        k += 2
    if n != 1:
        factor.append([n, 1])
    return factor

deg = [[0] * 9 for _ in range(9)]
fac = []

for _ in range(n):
    s = input()
    m = len(s)
    i = 0
    while i < m and s[i] != '.':
        i += 1
    if i == m:
        a = int(s) * 10 ** 4
    elif all(c == '0' for c in s[i+5:]):
        a = int(float(s) * 10 ** 4)
    else:
        continue

    d2, d5 = 0, 0
    while a % 2 == 0:
        d2 += 1
        a //= 2
    while a % 5 == 0:
        d5 += 1
        a //= 5
    d2 = min(d2, 8)
    d5 = min(d5, 8)
    deg[d2][d5] += 1
    fac.append((d2, d5))

count = 0
for d2, d5 in fac:
    for i in range(8 - d2, 9):
        for j in range(8 - d5, 9):
            count += deg[i][j]
    if d2 >= 8 - d2 and d5 >= 8 - d5:
        count -= 1
print(count // 2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())
d = defaultdict()

for _ in range(n):
    a = float(input())
    a = int(a * 10**10)
    cnt2 = -10
    cnt5 = -10
    while a % 2 == 0:
        cnt2 += 1
        a //= 2
    while a % 5 == 0:
        cnt5 += 1
        a //= 5
    if (cnt2, cnt5) in d:
        d[(cnt2, cnt5)] += 1
    else:
        d[(cnt2, cnt5)] = 1

ans = 0

for k1,v1 in d.items():
    for k2, v2 in d.items():
        x1, y1 = k1
        x2, y2 = k2
        if k1 != k2:
            if x1 + x2 >= 0 and y1 + y2 >= 0:
                ans += v1 * v2
        else:
            if x1 + x2 >= 0 and y1 + y2 >= 0:
                ans += v1 * (v1 - 1)

print(ans // 2)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
from math import gcd
n=int(input())
a=[input() for _ in range(n)]

aint = [Decimal(ai) for ai in a if not "." in ai]

afl = [Decimal(ai) for ai in a if "." in ai]

ans= len(aint)*(len(aint)-1)//2
cnts = {i:0 for i in range(1,10001) if 10000%i==0}

for i in cnts:
    for ai in afl:
        if i*ai==int(i*ai):
            cnts[i]+=1
for ai in aint:
    g= gcd(int(ai),10000)
    if g in cnts:
        ans+=cnts[g]

print(ans)

Submission status: Wrong Answer

Solution code:
"""
from math import gcd

n = int(input())
a = []

for _ in range(n):
    a1 = input()
    if '.' in a1:
        s = a1.split('.')
        b = [int(s[0] + s[1]), 10**len(s[1])]
        g = gcd(b[0], b[1])
        b[0] //= g
        b[1] //= g
    else:
        b = [int(a1), 1]
    print(b)
    a.append(b)

li1 = [[0] * 100 for i in range(100)]
li2 = [[0] * 100 for i in range(100)]

cnt = 0

for i,j in a:
    cnt2 = 0
    cnt5 = 0
    while i % 2 == 0:
        cnt2 += 1
        i //= 2
    while i % 5 == 0:
        cnt5 += 1
        i //= 5
    li1[cnt2][cnt5] += 1

    cnt2 = 0
    cnt5 = 0
    while j % 2 == 0:
        cnt2 += 1
        j //= 2
    while j % 5 == 0:
        cnt5 += 1
        j //= 5
    li2[cnt2][cnt5] += 1

print(li1[:5][:5])
"""

from collections import defaultdict

n = int(input())
d = defaultdict()

for _ in range(n):
    a = float(input())
    a = int(a * 10**9)
    cnt2 = -9
    cnt5 = -9
    while a % 2 == 0:
        cnt2 += 1
        a //= 2
    while a % 5 == 0:
        cnt5 += 1
        a //= 5
    if (cnt2, cnt5) in d:
        d[(cnt2, cnt5)] += 1
    else:
        d[(cnt2, cnt5)] = 1

ans = 0

for k1,v1 in d.items():
    for k2, v2 in d.items():
        x1, y1 = k1
        x2, y2 = k2
        if k1 != k2:
            if x1 + x2 >= 0 and y1 + y2 >= 0:
                ans += v1 * v2
        else:
            if x1 + x2 >= 0 and y1 + y2 >= 0:
                ans += v1 * (v1 - 1)

print(ans // 2)

Submission status: Wrong Answer

Solution code:
c=[[0]*50for _ in range(50)]
r=0
for a in[*open(0)][1:]:
  a=round(float(a)*10**9)
  x=y=0
  while a%2<1:
    a//=2
    x+=1
  while a%5<1:
    a//=5
    y+=1
  r+=sum(sum(d[max(0,18-x):])for d in c[max(0,18-y):])
  c[x][y]+=1
print(r)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
n = int(input())
a = []
r = {}
for i in range(n):
    d = int(float(input())*10**9+0.0001)
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in r.keys():
    for i , j in r.keys():
        if min(x+i,y+j) >= 18:
            ans += r[(x,y)]*r[(i,j)]
            if x == i and y == j:
                ans -= r[(x,y)]
                
print(ans//2)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from collections import defaultdict
dic = defaultdict(int)
for _ in range(N):
    a = float(input())*(10**9)
    a = int(a+0.1)
    num2, num5 = 0, 0
    while a%2==0:
        a//=2
        num2+=1
        if num2>18: break
    while a%5==0:
        a//=5
        num5+=1
        if num5>18: break
    dic[(num2, num5)] += 1

keys = list(dic.keys())
length = len(keys)
print(keys)
ans = 0
for i in range(length):
    a2, a5 = keys[i]
    a_cnt = dic[(a2, a5)]
    for j in range(i, length):
        b2, b5 = keys[j]
        b_cnt = dic[(b2, b5)]
        if a2+b2>=18 and a5+b5>=18:
            if i==j:
                ans += (a_cnt)*(b_cnt-1)//2
            else:
                ans += a_cnt*b_cnt
print(ans)

Submission status: Wrong Answer

Solution code:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    s25 = [[0]*19 for i in range(19)] #2^i*5^j*kの個数：s25[i][j]
    nms = [] #(i,j)の組
    n = int(ipt())
    for _ in range(n):
        a = float(ipt())*(10**9)+0.1
        ia = int(a)
        for i in range(19):
            if ia%2 != 0:
                t2 = i
                break
            elif i == 18:
                t2 = 18
            else:
                ia //= 2
        for i in range(19):
            if ia%5 != 0:
                t5 = i
                break
            elif i == 18:
                t5 = 18
            else:
                ia //= 5
        s25[18-t2][18-t5] += 1
        nms.append((t2,t5))

    ss = s25
    for i in range(1,19):
        ss[0][i] += ss[0][i-1]
        ss[i][0] += ss[0][i-1]
    for i in range(1,19):
        for j in range(1,19):
            ss[i][j] += ss[i-1][j]+ss[i][j-1]-ss[i-1][j-1]
#    print(ss)

    ans = 0
    for t2,t5 in nms:
        ans += ss[t2][t5]
        if t2 >= 9 and t5 >= 9:
            ans -= 1

    print(ans//2)

    return None

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

def factorize(n):
    factor = []
    if n % 2 == 0:
        f = [2, 1]
        n //= 2
        while n % 2 == 0:
            n //= 2
            f[1] += 1
        factor.append(f)

    k = 3
    while k * k <= n:
        if n % k == 0:
            f = [k, 1]
            n //= k
            while n % k == 0:
                n //= k
                f[1] += 1
            factor.append(f)
        k += 2
    if n != 1:
        factor.append([n, 1])
    return factor

deg = [[0] * 9 for _ in range(9)]
fac = []

for _ in range(n):
    f = float(input()) * 10000 # a < 10 ** 4 より
    if f != int(f):
        continue
    a = int(f)
    d2, d5 = 0, 0
    while a % 2 == 0:
        d2 += 1
        a //= 2
    while a % 5 == 0:
        d5 += 1
        a //= 5
    d2 = min(d2, 8)
    d5 = min(d5, 8)
    deg[d2][d5] += 1
    fac.append((d2, d5))

count = 0
for d2, d5 in fac:
    for i in range(8 - d2, 9):
        for j in range(8 - d5, 9):
            count += deg[i][j]
    if d2 >= 8 - d2 and d5 >= 8 - d5:
        count -= 1
print(count // 2)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
n = int(input())
a = []
r = {}
for i in range(n):
    d = int(float(input())*10**9)
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in r.keys():
    for i , j in r.keys():
        if min(x+i,y+j) >= 18:
            ans += r[(x,y)]*r[(i,j)]
            if x == i and y == j:
                ans -= r[(x,y)]
                
print(ans//2)

Submission status: Wrong Answer

Solution code:
c=[[0]*50for _ in range(50)]
r=0
for a in[*open(0)][1:]:
  a=round(float(a)*10**9)
  x=y=0
  while a&1<1:
    a>>=1
    x+=1
  while a%5<1:
    a//=5
    y+=1
  r+=sum(sum(d[max(0,18-x):])for d in c[max(0,18-y):])
  c[x][y]+=1
print(r)

Submission status: Wrong Answer

Solution code:
from subprocess import*
c=[[0]*50for _ in range(50)]
for a in[*open(0)][1:]:
  a,b=map(run(('factor',str(round(float(a)*10**9))),stdout=PIPE).stdout.split().count,(b'2',b'5'))

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []

for i in range(N):
   lst.append(float(input()))

lst.sort()

count = 0

for i in range(N):
   for j in range(i+1, N):
      if (lst[i] * 10**9) * (lst[j] * 10 ** 9) % (10 ** 18) == 0:
         count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
for _ in range(N):
    a.append(float(input()))
c=0
for i in range(N):
    for j in range(i+1,N):
        if a[i]*a[j]%1.0 == 0:
            c+=1
print(c)

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
    
    MULT = 10 ** 9
    for i, a in enumerate(A):
        if a == int(a):
            minus += 1
        a *= MULT
        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, -1, -1):
        for j in range(18, -1, -1):
            if i > 0:
                M[i-1][j] += M[i][j]
                
    for i in range(18, -1, -1):
        for j in range(18, -1, -1):
            if j > 0:
                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:
import decimal
n = int(input())

cum = [[0]*50 for i in range(50)]

l = []
for i in range(n):
    x = decimal.Decimal(input())
    x *= 10**9
    x = int(x)
    
    two = 0
    while x%2 == 0:
        x //= 2
        two += 1
    five = 0
    while x%5 == 0:
        x //= 5
        five += 1
    cum[two][five] += 1
    l.append((two,five))

for i in range(48,-1,-1):
    for j in range(48,-1,-1):
        cum[i][j] += cum[i][j+1]+cum[i+1][j]-cum[i+1][j+1]

ans = 0
for i,j in l:
    x = 18-i
    y = 18-j
    if x <= i and y <= j:
        ans += cum[x][y]-1
    else:
        ans += cum[x][y]
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(-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)