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: Time Limit Exceeded

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

from decimal import Decimal

def get_primes(n):
	divs = defaultdict(int)
	for i in [2,5]:
		c = 0
		while n % i == 0:
			n = n // i
			c += 1
		if c > 0:
			divs[i] = c
	return divs

L = 10**9
N = ri()
A = []
for i in range(N):
	d = Decimal(rs())
	A.append(int(d*L))
#print(A)

C = [[0, 0] for i in range(N)]
for i, r in enumerate(A):
	ps = get_primes(r)
	C[i] = [min(ps[2], 18), min(ps[5], 18)]
#print(C)

h = defaultdict(int)
ans = 0
for c in C:
	d = [18-c[0], 18-c[1]]
	for i in range(d[0], 19):
		for j in range(d[1], 19):
			if (i, j) in h:
				ans += h[(i,j)] - (c == (i,j))
	h[tuple(c)] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from decimal import Decimal

n = int(input())
a = []
for _ in range(n):
    a.append(Decimal(input()))
count = 0
for i in range(n-1):
    for j in range(n-i-1):
        result = Decimal(a[i] * a[i + j + 1])
        if math.isclose(result % 1, 0.00000, abs_tol=1e-100):
            count += 1
        # if result.is_integer():
        #     count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
N = int(input())
A = []
for _ in range(N):
    A.append(Fraction(input()))
ans=0
for i in range(N):
    for j in range(i+1,N):
        if (A[i].numerator * A[j].numerator ) % (A[i].denominator * A[j].denominator) == 0 :
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from decimal import Decimal

N, *A = map(Decimal, open(0).read().split())
N = int(N)
A.sort()

c = {}
intc = 0
ints = []
decs = []
for d in A:
    if d in c:
        c[d] += 1
        if d == int(d):
            intc += 1
    else:
        c[d] = 1
        if d == int(d):
            intc += 1
            ints.append(d)
        else:
            decs.append(d)

result = intc * (intc - 1) // 2
for i in range(len(decs)):
    a = decs[i]
    f = a - int(a)
    t = max(bisect_left(decs, 1 / a), i + 1)
    for j in range(t, len(decs)):
        b = decs[j]
        t = a * b
        if t == int(t):
            result += c[a] * c[b]

fras = sorted(set(d - int(d) for d in decs))
frac = {}
for d in decs:
    t = d - int(d)
    frac.setdefault(t, 0)
    frac[t] += c[d]

for i in range(len(fras)):
    a = fras[i]
    t = bisect_left(ints, 1 / a)
    for j in range(t, len(ints)):
        b = ints[j]
        t = a * b
        if t == int(t):
            result += frac[a] * c[b]

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def primes(n):
    a = Counter()
    while n % 2 == 0:
        a[2]+=1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f]+=1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n]+=1
    return a

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(str, input().split())) #1行ベクトル
    A = tuple(input() for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    dp=[[0]*19 for _ in range(19)]
    t9=10**9
    for a in A:
        ta=0
        base=1

        ta=round(float(a)*t9)

        
        c=primes(ta)
        n2=min(18,c[2])
        n5=min(18,c[5])
        t2=18-n2
        t5=18-n5
        for i in range(t2,19):
            for j in range(t5,19):
                ans+=dp[i][j]
        #printe(n2,n5,ans)
        dp[n2][n5]+=1
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from decimal import *

n = int(input())
ans = 0
vec = [Decimal(input()) for i in range(n)]
vec25 = [[0 for i in range(50)] for i in range(50)]  # 整数にするのに余っている2,5の数
for i in range(n):
    a = vec[i] * 1000000000
    num2 = -9
    num5 = -9
    while a%2 == 0:
        a //= 2
        num2 += 1
    while a%5 == 0:
        a //= 5
        num5 += 1
    vec25[num2][num5] += 1
for i in range(-9, 40): 
    for j in range(-9, 20):
        for k in range(max(-9, -i), 40):
            for l in range(max(-9, -j), 20):
                if i+k >= 0 and j+l >= 0 :
                    if i != k or j != l :
                        ans += vec25[i][j] * vec25[k][l]
                    else :
                        ans += vec25[i][j] * (vec25[i][j] - 1)
ans //= 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
from fractions import Fraction
N = int(input())
A = []
F = []
for i in range(N):
    x = Decimal(input())
    A.append(x)
    F.append(Fraction(x))

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if (F[i].numerator % F[j].denominator == 0) and (F[j].numerator % F[i].denominator == 0):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [float(input()) for _ in range(n)]
#B = list(map(lambda x:x%1,A))
B = list(map(lambda x:1/x,A))

cnt=0
for i in range(n-1):
  for j in range(i,n):
    if j ==i:
      continue
    product = 10**9*A[i]*A[j]
#    print(A[i],A[j],product)
    if (product)%10**9==0:
      cnt+=1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def primes(n):
    a = Counter()
    while n % 2 == 0:
        a[2]+=1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f]+=1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n]+=1
    return a

class BIT():#添字は1から始まることに注意
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
        self.tot=0
        
    def initialize(self,seq):
        tree = self.tree
        size = self.size
        self.tot=0
        for i,x in enumerate(seq,1):
            self.tot+=x
            tree[i] += x
            j = i+(i&(-i))
            if j < size:
                tree[j] += tree[i]
        
    def __repr__(self):
        return self.tree.__repr__()
        
    def sum(self,i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & -i
        return s
 
    def add(self, i, val):
        tree = self.tree
        size = self.size
        while i < size:
            tree[i] += val
            i += i & -i
        self.tot+=val
    
    def find(self,k):#k番目（最小は１）の要素,使うときは数列のサイズとbitのサイズを合わせること
        if k>self.tot: return self.size
        tree = self.tree; size = self.size
        x,sx = 0,0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + tree[y]
            if sy < k:
                x,sx = y,sy
        return x + 1

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(str, input().split())) #1行ベクトル
    A = tuple(input() for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    t9=10**9
    dp=[BIT(19) for _ in range(19)]
    for a in A:
        ta=0
        base=1
        dot=0

        ta=round(float(a)*t9)
        
        c=primes(ta)
        n2=min(18,c[2])
        n5=min(18,c[5])
        t2=18-n2
        t5=18-n5
        for i in range(t2,19):
            ans+=dp[i].sum(18-t5+1)
        #printe(n2,n5,ans)
        dp[n2].add(18-n5+1,1)
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
A = []

for i in range(N):
    s = input()
    if '.' in s:
        a,b = map(int,s.split('.'))
        if(int(b)==0):
            c = a
            d = 1
        else:
            c = a*pow(10,len(s)-s.find('.')-1)+b
            d = pow(10,len(s)-s.find('.')-1)
            g = math.gcd(c,d)
            c = c//g
            d = d//g
    else:
        c = int(s)
        d = 1
    e = 0
    f = 0
    while(c != 0 and c%2==0):
        e += 1
        c //= 2
    while(c != 0 and c%5==0):
        f += 1
        c //= 5
    while(d%2==0):
        e -= 1
        d //=2
    while(d%5==0):
        f -= 1
        d //=5
    A.append([e,f])

ans = 0

for i in range(len(A)-1):
    for j in range(i+1,len(A)):
        if (A[i][0]+A[j][0]>=0) and (A[i][1]+A[j][1]>=0):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

from decimal import Decimal

def get_primes(n):
	#divs = []
	divs = defaultdict(int)
	for i in range(2, int(n**0.5)+1):
		c = 0
		while n % i == 0:
			n = n // i
			c += 1
		if c > 0:
			#divs.append((i, c))
			divs[i] = c
	if n > 1:
		#divs.append((n, 1))
		divs[n] = 1
	return divs

L = 10**9
N = ri()
A = []
for i in range(N):
	d = Decimal(rs())
	A.append(int(d*L))
#print(A)

C = [[0, 0] for i in range(N)]
for i, r in enumerate(A):
	ps = get_primes(r)
	#print(r, ps)
	C[i] = [min(ps[2], 18), min(ps[5], 18)]
#print(C)

h = defaultdict(int)
#for c in C:
#print(h)
ans = 0
for c in C:
	#print('c',c)
	d = [18-c[0], 18-c[1]]
	for i in range(d[0], 19):
		for j in range(d[1], 19):
			if (i, j) in h:
				#print('ok', i, j)
				ans += h[(i,j)] - (c == (i,j))
	h[tuple(c)] += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = round(float(input())*(10**9))
floatans=0
for i in range(N):
    for j in range(i+1,N):
        if (A[i]*A[j])%(10**18)==0:
            floatans+=1
print(floatans)

Submission status: Time Limit Exceeded

Solution code:
from decimal import  Decimal, ROUND_HALF_UP

n = int(input())
a_list = []
for i in range(n):
    a = Decimal(input())
    a_list.append(a)

flag = 0
for i in range(n):
    a_i = a_list[i]
    for j in range(i+1, n):
        a_j = a_list[j]
        A = a_i * a_j
        if A == Decimal(A).quantize(Decimal('0'), rounding=ROUND_HALF_UP):
            flag += 1

print(flag)

Submission status: Time Limit Exceeded

Solution code:
def cchange(c):
  if c == '0':
    return ''
  elif c [-1] == '0':
    c = cchange(c[:-1])
    return c
  else:
    return c

def count5(num,m):
  if num % 5 == 0:
    mm = count5(num//5,m+1)
    return mm
  else:
    return m
  
def count2(num,m):
  if num % 2 == 0:
    mm = count2(num//2,m+1)
    return mm
  else:
    return m

n = int(input())
l = [0]*n
for i in range(n):
  a = input()
  if not '.' in a:
    a = int(a)
    l[i] = [a, count5(a,0), count2(a,0)]
  else:
    b,c = a.split('.')
    c = cchange(c)
    if c == '':
      a = int(b)
      l[i] = [a, count5(a,0), count2(a,0)]
    else:
      a = int(b+c)
      l[i] = [a, count5(a,0)-len(c), count2(a,0)-len(c)]
      
count = 0

for i in range(n):
  for j in range(i+1,n):
    if l[i][1] + l[j][1] >= 0 and l[i][2] + l[j][2] >= 0:
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
N = int(input())
nu=[]
de=[]
for i in range(N):
    a=input()
    aa=Decimal(a).as_integer_ratio() #(1,3)など
    if aa[1]<10**4:
        nu.append(aa[0])
        de.append(aa[1])
ans=0
for i in range(len(nu)-1):
    for j in range(i+1,len(nu)):
        if nu[i]%de[j]==0 and nu[j]%de[i]==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = []
new_lst = []
c = 0
for x in range(0, N):
    ele = float(input())
    ele9 = round(ele, 9)
    lst.append(ele)
for i in lst:
    for j in lst:
        if i < j:
            a = i * j
            new_lst.append(a)
for b in new_lst:
    if b.is_integer():
        c += 1
    else:
        c += 0
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [float(input()) for _ in range(n)]

cnt = 0
for i in a[::-1]:
    for j in a[::-1]:
        if i != j:
            mul = i * j
            is_int = mul.is_integer()
            if is_int:
                cnt += 1
    a.pop()
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

def f(x, y):
    return x*y

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

a = np.array(A)
b = a%1
c = a[(b>1e-5) | (b==0)]

c = list(combinations(c, 2))


cnt = 0
for i in c:
    a0 = str(i[0])[-1]
    a1 = str(i[1])[-1]
    if int(a0)*int(a1) % 10 == 0:
        if f(i[0],i[1]) - int(f(i[0],i[1])) == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from decimal import Decimal

N, *A = map(Decimal, open(0).read().split())
N = int(N)
A.sort()

c = {}
intc = 0
ints = []
decs = []
for d in A:
    if d in c:
        c[d] += 1
        if d == int(d):
            intc += 1
    else:
        c[d] = 1
        if d == int(d):
            intc += 1
            ints.append(d)
        else:
            decs.append(d)

result = intc * (intc - 1) // 2
for i in range(len(decs)):
    a = decs[i]
    f = a - int(a)
    t = max(bisect_left(decs, 1 / a), i + 1)
    for j in range(t, len(decs)):
        b = decs[j]
        t = a * b
        if t == int(t):
            #print(a, b)
            result += c[a] * c[b]

    t = bisect_left(ints, 1 / f)
    for j in range(t, len(ints)):
        b = ints[j]
        t = a * b
        if t == int(t):
            #print(a, b)
            result += c[a] * c[b]

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math

N=int(input())
a=[input() for x in range(N)]
count=0

for number in a:
	for numbers in a:
		if number<numbers:
			i=float(number)*float(numbers)
			j=math.ceil(float(number)*float(numbers))
			if i%j==0:
				count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
import bisect

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = [int(float(input())*10**9) for i in range(n)]
ans = 0

for i in range(len(a)):
	for j in range(i+1,len(a)):
		if a[i]*a[j]%10**18==0:
			ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = [int(float(input().rstrip())*10**9) for _ in range(n)]
    ans = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            p = a[i]*a[k]%10**18
            if p == 0:
                ans += 1
    print(ans)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
N = int(input())
nu=[]
de=[]
for i in range(N):
    a=input()
    aa=Decimal(a).as_integer_ratio() #(1,3)など
    if aa[1]<10**4:
        nu.append(aa[0])
        de.append(aa[1])
ans=0
for i in range(len(nu)-1):
    for j in range(i+1,len(nu)):
        if (nu[i]*nu[j])%(de[i]*de[j])==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
for i in range(N):
  x=float(input())
  A+=[x]

def is_int(x,y):
  m=min(x,y)
  M=max(x,y)
  m=m*10000
  z=M*m/10000
  if (int(z)==z):
    return True
  return False

count=0
for i in range(N-1):
  for j in range(i+1,N):
    if is_int(A[i],A[j]):
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def primes(n):
    a = Counter()
    while n % 2 == 0:
        a[2]+=1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f]+=1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n]+=1
    return a

class BIT():#添字は1から始まることに注意
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        self.depth = self.size.bit_length()
        self.tot=0
        
    def initialize(self,seq):
        tree = self.tree
        size = self.size
        self.tot=0
        for i,x in enumerate(seq,1):
            self.tot+=x
            tree[i] += x
            j = i+(i&(-i))
            if j < size:
                tree[j] += tree[i]
        
    def __repr__(self):
        return self.tree.__repr__()
        
    def sum(self,i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & -i
        return s
 
    def add(self, i, val):
        tree = self.tree
        size = self.size
        while i < size:
            tree[i] += val
            i += i & -i
        self.tot+=val
    
    def find(self,k):#k番目（最小は１）の要素,使うときは数列のサイズとbitのサイズを合わせること
        if k>self.tot: return self.size
        tree = self.tree; size = self.size
        x,sx = 0,0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + tree[y]
            if sy < k:
                x,sx = y,sy
        return x + 1

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(str, input().split())) #1行ベクトル
    A = tuple(input() for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    dp=[BIT(19) for _ in range(19)]
    for a in A:
        ta=0
        base=1
        dot=0
        for i in range(len(a)):
            ai=a[-1-i]
            if ai==".":
                dot=i
            else:
                ta+=base*int(ai)
                base*=10
        
        c=primes(ta)
        n2=min(18,c[2]+(9-dot))
        n5=min(18,c[5]+(9-dot))
        t2=18-n2
        t5=18-n5
        for i in range(t2,19):
            ans+=dp[i].sum(18-t5+1)
        #printe(n2,n5,ans)
        dp[n2].add(18-n5+1,1)
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [input() for i in range(n)]
for i in range(n):
  if '.' in a[i]:
    a[i] = float(a[i])
  else:
    a[i] = int(a[i])
  
ans = 0
count = 0

for i in range(n):
  for j in range(i + 1, n):
    ans = (a[i]*10) * (a[j]*10)
    ans = ans*0.01
    if isinstance(ans, int):
      count += 1
    elif ans.is_integer():
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from decimal import Decimal

N = int(input())
A = [Decimal(input()) for _ in range(N)]

Z = np.zeros((50,50), dtype=int)

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

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

answer = 0
for i in range(N):
  a = int(A[i]*10**9)
  c2 = count2(a)
  c5 = count5(a)
  t2 = max(18-c2,0)
  t5 = max(18-c5,0)
  if i>0:
    answer += np.sum(Z[t2:,t5:])
  Z[c2,c5] += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
from decimal import Decimal

N, *A = map(Decimal, open(0).read().split())
N = int(N)
A.sort()

c = {}
intc = 0
ints = []
decs = []
for d in A:
    if d in c:
        c[d] += 1
        if d == int(d):
            intc += 1
    else:
        c[d] = 1
        if d == int(d):
            intc += 1
            ints.append(d)
        else:
            decs.append(d)

result = intc * (intc - 1) // 2
for i in range(len(decs)):
    a = decs[i]
    if a < 1:
        t = bisect_left(decs, 1 / a)
    else:
        t = i + 1
    for j in range(t, len(decs)):
        b = decs[j]
        t = a * b
        if t == int(t):
            #print(a, b)
            result += c[a] * c[b]

    f = a - int(a)
    t = bisect_left(ints, 1 / f)
    for j in range(t, len(ints)):
        b = ints[j]
        t = a * b
        if t == int(t):
            #print(a, b)
            result += c[a] * c[b]

print(result)

Submission status: Time Limit Exceeded

Solution code:
from decimal import *
n = int(input())
T = 45
F = 19
a = [[0 for i in range(F)] for j in range(T)]
p = pow(10,9)
two_size = 18
five_size = 18
count = 0
for i in range(n):
    k = Decimal(input()) * p
    two = 0
    five = 0
    while k % 2 == 0:
        two += 1
        k //= 2
    while k % 5 == 0:
        five += 1
        k //= 5
    t, f = two_size - two, five_size - five
    for x in range(t, T):
        for y in range(f, F):
            count += a[x][y]
    a[two][five] += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from decimal import *

N = int(input())
A = list()
for i in range(N):
    A.append(Decimal(input()))
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if (A[i]*A[j])%1==Decimal('0'):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = round(float(input())*(10**9))
from itertools import combinations
base = list(combinations(A,2))
floatans=0
for i in range(len(base)):
    a=base[i][0]*base[i][1]
    if a%(10**18)==0:
        floatans+=1
print(floatans)

Submission status: Time Limit Exceeded

Solution code:
from decimal import *

n = int(input())

numbers = []

for _ in range(n):
    numbers.append(Decimal(input()))

int_counter = 0

for i in range(n - 1):
    number = numbers[i]

    for j in range(i + 1, n):
        product = number * numbers[j]

        if not product.compare(product.quantize(Decimal('0'), rounding=ROUND_FLOOR)):
            int_counter += 1

print(int_counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
count=0
for i in range(1,n+1):
  a=int(float(input())*(10**9))
  for j in s:
    k=str(a*j)
    #print(k,k[-18:])
    if (k[-18:] == '000000000000000000'):
      count+=1
      #print(i,a,j,count)
  s.append(a)
print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys
from decimal import Decimal


def std_in():
    return sys.stdin.readline().strip()


def main():
    n = int(std_in())
    a = [Decimal("0.0")] * n
    for i in range(n):
        a[i] = Decimal(std_in())
    counter = 0
    for i in range(n-1):
        for j in range(i+1, n):
            p = a[i] * a[j]
            if (p - Decimal(int(p))) == Decimal("0"):
                counter += 1
    print(counter)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = round(float(input())*(10**9))
floatans=0
for i in range(N):
    for j in range(i+1,N):
        a = A[i] * A[j]
        if a%(10**18)==0:
            floatans+=1
print(floatans)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
n = int(input())
a = [Decimal(input()) for i in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if (a[i] * a[j]) % 1 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal

N = int(input())
A = []

for idx in range (N):
    A.append(Decimal(input()))

result = 0

for idx in range(0,N):
    for idx2 in range(idx+1,N):
        if A[idx] % 1 == 0 and A[idx2] % 1 ==0:
            result += 1
        elif A[idx] * A[idx2] % 1 == 0:
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [0.0] * N
for i in range(N):
    a[i] = float(input())
a.sort()
c = 0
pa1 = -1.0
for i in range(N):
  if (pa1 == a[i]):
    if (int(pa1) == pa1):
      c = c + pc - 1
    else:
      c = c + pc
    continue;
  f = 0
  pa2 = -1.0
  for j in range(i+1,N):
    if (pa2 == a[j]):
      c = c + f
      continue;
    else:
      f = 0
    pa2 = a[j]
    p = a[i]*a[j]
    if (int(p) == p):
      x = int(a[i]*1000000000)
      y = int(a[j]*1000000000)
      if ((x*y)%1000000000000000000 == 0):
        f = 1
        c = c + 1
print(c)