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:
from decimal import Decimal
N = int(input())
nu=[]
de=[]
integ=[]
for i in range(N):
    a=input()
    aa=Decimal(a).as_integer_ratio() #(1,3)など
    if aa[1]==1:
        integ.append(aa[0])
    elif aa[1]<10**3:
        nu.append(aa[0])
        de.append(aa[1])
ans=int(len(integ)*(len(integ)-1)/2)
for i in range(len(nu)):
    for j in range(len(integ)):
        if integ[j]%de[i]==0:
            ans+=1
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:
import pprint
N=int(input())
l2=[]
bit2=50
bit5=22
#table=[[0 for _ in range(20)] for _ in range(15)]
#table=[[0 for _ in range(45)] for _ in range(20)]
table=[[0 for _ in range(bit2)] for _ in range(bit5)]
from decimal import *
getcontext().prec=28
for i in range(N):
    pf={}
    n=float(input())
    #print(n)
    n=n*pow(10,9)
    count2=0
    count5=0
    n=Decimal(n)
    #print(n,kake)
    while n/2==n//2:
        n=n//2
        count2=count2+1
    while n/5==n//5:
        n=n//5
        count5=count5+1
    table[count5][count2]=table[count5][count2]+1
    l2.append([count2,count5])
#pprint.pprint(table)
#print(l2)
ans=0
for i in range(bit5):
    for j in range(bit2):
        num=table[i][j]
        min2=max(0,18-j)
        min5=max(0,18-i)
        cnt=0
        if num>0:
            #print(min2,min5,i,j,num)
            for k in range(min5,bit5):
                for l in range(min2,bit2):
                    cnt=cnt+table[k][l]
            if (min2<=j)and(min5<=i):
                cnt=cnt-1
            ans=ans+num*cnt
            #print(ans)
print(ans//2)

Submission status: Time Limit Exceeded

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

for i in range(n):
  for j in range(i + 1, n):
    if a[i] - int(a[i]) == 0 and a[j] - int(a[j]) == 0:
      count += 1
    else:
      ans = (a[i]*10000) * (a[j]*10000)
      ans = ans*0.00000001
      if ans - int(ans) == 0:
      	count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:

from fractions import Fraction
from decimal import Decimal
n = int(input())
a = []
b = []
for i in range(0,n):
	c = float(input())
	a.append(c)
	d = str(a[i])
	f = Fraction(Decimal(d))
	b.append(f)

x = []
y = []

for i in range(0,n):
	x.append(b[i].numerator)
	y.append(b[i].denominator)

count = 0

for i in range(0,n)	:
	for j in range(i+1,n):
		if (x[i]*x[j]) % (y[i]*y[j]) == 0:
			count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from sys import stdin
    from decimal import Decimal
    import numpy as np
    # read
    readline = stdin.readline
    n = int(readline())
    a = [Decimal(readline()) for _ in range(n)]
    a = np.array(a)
    count = 0
    for i in range(n - 1):
        count = count + np.count_nonzero((a[i + 1:] * a[i]) % 1 == 0)
    print(count)


main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [float(input()) for i in range(N)]
ans = 0
for i in a:
    if 0 < (i % 1) < 10**(-4):
        a.remove(i)
M = len(a)
for i in range(M-1):
    for j in range(i+1, M):
        if (a[i]*a[j]).is_integer():
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, *a = map(float, open(0).read().split())

m = 1000000000
m2 = m*m
n = int(n)

for i in range(n):
  a[i] = int( a[i] * m )
#  print(a[i])
#
cnt = 0
for i in range(n):
  if a[i] == 0:
    cnt += n-1 - i
    continue
#
  for j in range(i+1, n):
    if (a[i]*a[j]) % m2 == 0:
      cnt += 1
#
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n):
  for j in range(i + 1, n):
    ans = (a[i]*10000) * (a[j]*10000)
    ans = ans*0.00000001
    if ans - int(ans) == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l=[(0,0)]*N
fint=[False]*N
ans = 0
DMOD=10**9

for i in range(N):
    s=input()
    if '.' in s:
        idx = s.index('.')
        ndec=len(s)-1 - idx
        ai = int(s[:idx])
        ad = int(s[idx+1:])
        ad *= 10**(9-ndec)
        fint_i=False
    else:
        ad = 0
        ai = int(s)
        fint_i=True
    fint[i] = fint_i
    l[i]=(ai,ad)
    for j in range(i):
        ai_j,ad_j = l[j]
        fint_j = fint[j]

        if fint_i and fint_j:
            ans += 1
            continue
        a1=ad*ad_j
        c=a1//DMOD
        a1%=DMOD
        if a1!=0:
            continue
        a2=ai*ad_j + c
        a2%=DMOD
        a2+=(ad*ai_j)%DMOD
        a2%=DMOD
        if a2 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A2 = []
maxx2 = 0
maxx5 = 0
maxy = 0

for i in range(1, N+1):
  A = input()
  x2 = 0
  x5 = 0
  y = 0
  buf = [0, 0, 0]
  j = 0
  l = len(A)
  for a in A[::-1]:
    if a == ".":
      buf[2] = j
      A = A[:l-j-1] + A[l-j:]
      maxy = max(maxy, j)
      break
    j += 1
    if j > 9:
      break
  A = int(A)
  j = 0
  B = A
  while B%2==0:
    j += 1
    B = B//2
  buf[0] = j
  maxx2 = max(maxx2, j)
  j = 0
  B = A
  while B%5==0:
    j += 1
    B = B//5
  buf[1] = j
  maxx5 = max(maxx5, j)
  A2.append(buf)

dic = [[[0 for z in range(maxy+1)] for y in range(maxx5+1)] for x in range(maxx2 + 1)]
for x, y, z in A2:
  dic[x][y][z] += 1

dic = np.array(dic)
X = np.zeros_like(dic)
for i in range(maxx2+1):
  X[i,:,:] = i
Y = np.zeros_like(dic)
for i in range(maxx5+1):
  Y[:,i,:] = i
Z = np.zeros_like(dic)
for i in range(maxy+1):
  Z[:,:,i] = i

X = X-Z
Y = Y-Z

ans = 0
for x, y, z in A2:
  dic[x][y][z] -= 1
  ans += dic[np.logical_and(X >= z-x, Y >= z-y)].sum()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from decimal import Decimal

number_set = list()
i = 1
u = 0

a = int(input())
while i <= a:
    z = Decimal(input())
    number_set.append(z)
    i += 1

for pair in itertools.combinations(number_set, 2):
    if (pair[0] * pair[1])-int((pair[0] * pair[1])) == 0:
        u += 1

print(u)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if A[i]*A[j] == Decimal(str(int(A[i]*A[j]))):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l=[(0,0)]*N
fint=[False]*N
ans = 0
DMOD=10**9

for i in range(N):
    s=input()
    if '.' in s:
        idx = s.index('.')
        ndec=len(s)-1 - idx
        ai = int(s[:idx])
        ad = int(s[idx+1:])
        ad *= 10**(9-ndec)
        fint_i=False
    else:
        ad = 0
        ai = int(s)
        fint_i=True
    fint[i] = fint_i
    l[i]=(ai,ad)
    for j in range(i):
        ai_j,ad_j = l[j]
        fint_j = fint[j]

        if fint_i and fint_j:
            ans += 1
            continue
        a1=ad*ad_j
        c=a1//DMOD
        a1%=DMOD
        a2=ai*ad_j + c
        a2%=DMOD
        a2+=(ad*ai_j)%DMOD
        a2%=DMOD
        if a1==0 and a2 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

for i in range(N):
    A[i] = round(float(input())/0.000000001)

s = 0

for i in range(N):
    for j in range(N):
        if j <= i:
            continue

        if round((A[i]*A[j])%(1000000000000000000)) == 0:
            s += 1

print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from decimal import Decimal

number_set = list()
i = 1
u = 0
y = 0


a = int(input())
while i <= a:
    z = Decimal(input())
    number_set.append(z)
    i += 1


for pair in itertools.combinations(number_set, 2):
    if (pair[0] * pair[1])-int((pair[0] * pair[1])) == 0:
        u += 1

print(u)

Submission status: Time Limit Exceeded

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        temp = int(a[i]*10**9) * int(a[j]*10**9)
        if (temp % 10**18 == 0):
            ans+=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):
    ai = a[i]
    for j in range(n-i-1):
        result = Decimal(ai * a[i + j + 1])
        if result % 1 == 0:
            count += 1

print(count)

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)
    nf = 1 - f
    t = max(bisect_left(decs, 1 / min(nf, f)), 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 / min(a, 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 itertools
from decimal import Decimal

number_set = list()
i = 1
u = 0
y = 0

a = int(input())
while i <= a:
    z = Decimal(input())
    number_set.append(z)
    i += 1

for pair in itertools.combinations(number_set, 2):
    x = (pair[0] * pair[1])-int((pair[0] * pair[1]))
    if x == 0:
        u += 1

print(u)

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque
from decimal import Decimal
import math

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    N=int(input())
    A=[]
    d=[0]*N #少数点以下の桁数
    two=[0]*N #２で割れる回数
    five=[0]*N  #5で割れる回数

    for i in range(N):
        tmp=input()
        d_A=Decimal(tmp)
        split=list(tmp.split('.'))
        if len(split)==2:
            d[i]=len(str(Decimal('0.'+split[1])))-1
            # print('split[1]=',split[1],' str=',str(Decimal(split[1])))
        int_d_A=d_A*(10**d[i])
        while int_d_A%2==0:
            int_d_A//=2
            two[i]+=1
        while int_d_A%5==0:
            int_d_A//=5
            five[i]+=1
        # print(split)
        A.append(d_A)
        # print('num=',tmp,' d=',d[i],' two=',two[i],' five=',five[i])

        two[i]-=d[i]    #余ってる数
        five[i]-=d[i]

    ans=0
    for n in list(itertools.combinations(list(range(N)),2)):
        if two[n[0]]+two[n[1]]>=0 and five[n[0]]+five[n[1]]>=0:
            ans+=1


    # for i in range(N-1):
    #     for j in range(i+1, N):
    #         # if (A[i]*A[j])%1==0:
    #         if min(two[i] + two[j], five[i] + five[j]) >= d[i] + d[j]:
    #             # print('two=',two[i] + two[j],' five=',five[i] + five[j], 'd=',d[i] + d[j])
    #             # print('A[i]=',A[i],' A[j]=',A[j],' A[i]*A[j]=',A[i]* A[j])
    #             ans+=1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

AA={}  

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

count=0
for i in range(N-1):
  for j in range(i+1,N):
    if is_int(A[i],A[j]):      
#      t=(A[i],A[j])
#      if not t in AA:
#        AA[t]=1
#      else:
#        AA[t]+=1
      count+=1

#for k in AA.keys():
#  print('AA[{}]={}'.format(k,AA[k]))
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from sys import stdin
    from decimal import Decimal
    import numpy as np
    # read
    readline = stdin.readline
    n = int(readline())
    a = [Decimal(readline()) for _ in range(n)]
    a = np.array(a)
    count = 0
    for i in range(n - 1):
        b = a[i + 1:]
        count = count + np.count_nonzero((b * a[i]) % 1 == 0)
    print(count)


main()

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

A_list = []
A_list_seisu = []
A_list_syosu = []
A_list_syosu_modi = []
A_list_log = []
cnt = 0

for i in range(0, N):
    a = float(input())
    A_list.append(a)

for i in range(0, N):
    A_list_seisu.append(int(A_list[i]))
    A_list_syosu.append(A_list[i] - A_list_seisu[i])
    if A_list_syosu[i] != 0.0:
        if math.log10(A_list[i] - A_list_seisu[i]) >= -5:
            #A_list_log.append(ath.log10(A_list[i] - A_list_seisu[i]))
            A_list_log.append(A_list[i])
    else:
        #A_list_log.append(1)
        A_list_log.append(A_list[i])


for i in range(0, len(A_list_log)-1):
    for j in range(i+1, len(A_list_log)):
        A_mul = A_list_log[i]*A_list_log[j]
        A_mul_seisu = int(A_mul)
        A_mul_syosu = A_mul - A_mul_seisu
        if A_mul_syosu == 0.0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
n = int(input())
a = [Decimal(input()) for _ in range(n)]
res = 0
for i,j in enumerate(a):
  for k in a[i+1:]:
    tmp = j*k
    if tmp-tmp//1 < 1e-19:
      res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [float(input()) for i in range(N)]
#A = [len(input()) for i in range(N)]
count = 0
B = []
C = []

for i in range(N):
    if A[i] % 1 == 0:
        B.append(A[i])
    elif A[i] >= 0.00001:
        C.append(A[i])

for i in range(len(B)):
    count += i

for i in B:
    for j in C:
        if ((i * j) % 1 == 0):
            count += 1

for i in range(len(C)):
    for j in range(i+1, len(C)):
        if ((C[i] * (10 ** 4)) * (C[j] * (10 ** 4))) % (1 * (10 ** 4) ** 2) == 0:
            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
def daccumulate(s):#二次元累積和
    n=len(s); m=len(s[0])
    acc=[[0]*m for _ in range(n)]
    for i in range(n):
        si=s[i]; ai=acc[i]
        for j in range(m):
            tot=si[j]
            if i>0: tot+=acc[i-1][j]
            if j>0:
                tot+=ai[j-1]
                if i>0: tot-=acc[i-1][j-1]
            ai[j]=tot
    return acc

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
    bas=100

    for a in A:
        ta=0


        ta=round(float(a)*t9)

        
        c=primes(ta)
        n2=min(18,c[2])
        n5=min(18,c[5])
        dp[18-n2][18-n5]+=1
    ddp=daccumulate(dp)
    ans=0

    for i in range(19):
        for j in range(19):
            t2=18-i
            t5=18-j
            c=dp[t2][t5]
            ta=ddp[i][j] 
            if i*2>=18 and j*2>=18:
                ta-=c
                ans+=c*(c-1)
            ans+=ta*c

    print(ans//2)
               




if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal 
from sys import stdin
import math

input = stdin.readline
def fac(n: int):
    if n <= 1:
        return 0
    elif n == 2:
        return 1
    else:
        return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

def main():
    N = int(input().rstrip())
    ans = 0
    A = []
    B = []
    for _ in range(N):
        t = Decimal(input().rstrip())
        if t == Decimal(int(t)):
            B.append(t)
        else:
            A.append(t)
    ans += fac(len(B))
    for i, a in enumerate(A):
        for ii, aa in enumerate(A + B):
            if i >= ii:
                continue
            p = aa * a
            pp = Decimal(int(p))
            if p == pp:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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 / f), 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:
N = int(input())
l=[(0,0)]*N
fint=[False]*N
ans = 0
DMOD=10**9

for i in range(N):
    s=input()
    if '.' in s:
        idx = s.index('.')
        ndec=len(s)-1 - idx
        ai = int(s[:idx])
        ad = int(s[idx+1:])
        ad *= 10**(9-ndec)
        fint_i=False
    else:
        ad = 0
        ai = int(s)
        fint_i=True
    fint[i] = fint_i
    l[i]=(ai,ad)
    for j in range(i):
        ai_j,ad_j = l[j]
        fint_j = fint[j]

        if fint_i and fint_j:
            ans += 1
            continue
        a1=ad*ad_j
        c=a1//DMOD
        a1%=DMOD
        a2=ai*ad_j + c
        a2%=DMOD
        a2+=ad*ai_j
        a2%=DMOD
        if a1==0 and a2 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [float(input()) for i in range(N)]
#A = [len(input()) for i in range(N)]
count = 0
B = []
C = []

for i in range(N):
    if A[i] % 1 == 0:
        B.append(A[i])
    elif A[i] >= 0.00001:
        C.append(A[i])

for i in range(len(B)):
    count += i

for i in B:
    for j in C:
        if ((i * j) % 1 == 0):
            count += 1

for i in range(len(C)):
    for j in range(i+1, len(C)):
        if ((C[i] * (10 ** 5)) * (C[j] * (10 ** 5))) % (1 * (10 ** 5) ** 2) == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
from decimal import Decimal
n=int(input())
alist=[0]*200001
blist=[]
clist=[]
num2=0
num=0
for i in range(n):
  a=float(input())
  if a.is_integer():
    num+=1
    for i in make_divisors(int(a)):
      alist[i]+=1
  else:
    b=str(a)
    c=Decimal(b).as_integer_ratio()
    blist.append(c[1])
    clist.append(c)
    num2+=1
ans=0
for i in blist:
  if i<200001:
    ans+=alist[i]
ans+=num*(num-1)//2
for i in range(num2):
  for j in range(i+1,num2):
    if clist[i][0]%clist[j][1]==0:
      if clist[j][0]%clist[i][1]==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from decimal import Decimal

number_set = list()
i = 1
u = 0
y = 0


a = int(input())
while i <= a:
    z = Decimal(input())
    number_set.append(z)
    i += 1


for pair in itertools.combinations(number_set, 2):
    x = pair[0] * pair[1]
    z = x-int(x)
    if z == 0:
        u += 1

print(u)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from decimal import *
N = int(input())
A = []
for i in range(N):
    a = Decimal(input())
    A.append(a)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

a = 0.0
b = 0.0
A = []
for _ in range(N):
  A.append(int(float(input()) * 1000000000))

count = 0
v = 0
for i in range(N):
  for j in range(i+1, N):
    v = A[i] * A[j]
    if (v % 1000000000000000000) == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
a = [float(input()) for i in range(n)]
  
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:
from decimal import Decimal
n = int(input())
a = [float(input()) for i in range(n)]
count = 0
for i in range(n):
    for j in range(1+i,n):
        if (Decimal(str(a[i])) * Decimal(str(a[j]))%1) == 0:
            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()))
    A.append(int(float(input())*10**9))
ans=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]*A[j] % 10**18 == 0 :
            ans += 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.0, abs_tol=1e-15):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import decimal
N=int(input())
nums=[]
count=0
for i in range(N):
  a=decimal.Decimal(input())
  nums.append(a)
k=1
for i in range(N):
  for j in range(k, N):
    b=nums[i]*nums[j]
    if b == int(b):
      count+=1
  k+=1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=[]
for i in range(n):
    s=input()
    if '.' in s:
        u=s.index('.')
        a=int(s[:u]+s[u+1:])
        b=len(s)-u-1
        L.append((a,b))
    else:
        L.append((int(s),0))
ans=0
for i in range(n):
    for j in range(i+1,n):
        dat=L[i][0]*L[j][0]
        ld=L[i][1]+L[j][1]
        M=10**ld
        c=dat//M
        if c*M==dat:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
N = int(input())
nu=[]
de=[]
integ=[]
for i in range(N):
    a=input()
    aa=Decimal(a).as_integer_ratio() #(1,3)など
    if aa[1]==1:
        integ.append(aa[0])
    elif aa[1]<10**4:
        nu.append(aa[0])
        de.append(aa[1])
ans=int(len(integ)*(len(integ)-1)/2)
for i in range(len(nu)):
    for j in range(len(integ)):
        if integ[j]%de[i]==0:
            ans+=1
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:
from decimal import Decimal, getcontext

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

for i in range(n):
    b = Decimal(input())
    a.append(b)

for i in range(n-1):
    for j in range(i+1,n):
        if int(a[i]*a[j]) - (a[i]*a[j]) == 0:
            c = c + 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
n = int(input())
a = []
for _ in range(n):
  a.append(input())
res = 0
for i,j in enumerate(a):
  for k in a[i+1:]:
    tmp = Decimal(j)*Decimal(k)
    if tmp-tmp//1 < 1e-19:
      res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
import decimal
N=int(input())
nums=[]
count=0
for i in range(N):
  a=decimal.Decimal(input())
  nums.append(a)
k=1
for i in range(N):
  for j in range(k, N):
    if nums[i]*nums[j] == int(nums[i]*nums[j]):
      count+=1
  k+=1

print(count)

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(ele9)
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
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque
from decimal import Decimal
import math

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    N=int(input())
    A=[]
    d=[0]*N #少数点以下の桁数
    two=[0]*N #２で割れる回数
    five=[0]*N  #5で割れる回数

    for i in range(N):
        tmp=input()
        d_A=Decimal(tmp)
        split=list(tmp.split('.'))
        if len(split)==2:
            d[i]=len(str(Decimal('0.'+split[1])))-1
            # print('split[1]=',split[1],' str=',str(Decimal(split[1])))
        int_d_A=d_A*(10**d[i])
        while int_d_A%2==0:
            int_d_A//=2
            two[i]+=1
        while int_d_A%5==0:
            int_d_A//=5
            five[i]+=1
        # print(split)
        A.append(d_A)
        # print('num=',tmp,' d=',d[i],' two=',two[i],' five=',five[i])



    ans=0
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            # if (A[i]*A[j])%1==0:
            if min(two[i] + two[j], five[i] + five[j]) >= d[i] + d[j]:
                # print('two=',two[i] + two[j],' five=',five[i] + five[j], 'd=',d[i] + d[j])
                # print('A[i]=',A[i],' A[j]=',A[j],' A[i]*A[j]=',A[i]* A[j])
                ans+=1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from decimal import *
import itertools
n = int(input())
arr = []
count = 0
for _ in range(n):
    arr.append(Decimal(input()))

for pair in itertools.combinations(arr, r=2):
    p = (pair[0]*pair[1])
    if p == int(p):
        count += 1
print(count)

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(ele9)
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:
def main():
    from sys import stdin
    from decimal import Decimal
    import numpy as np
    # read
    readline = stdin.readline
    n = int(readline())
    a = [Decimal(readline()) for _ in range(n)]
    a = np.array(a)
    count = 0
    for i in range(n - 1):
        shift = np.roll(a, i + 1)
        b = (a * shift)
        c = np.count_nonzero(b % 1 == 0)
        count = count + c
    print(int(count / 2))


main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np


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

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

cnt = 0
for i in range(len(c)):
    for n in range(i+1, len(c)):
       if c[i]*c[n] % 1 == 0:
           cnt += 1
    
print(cnt)