Since only people with a rating of 1200 or higher are related to the rating, I thought that 0 completion would not be a problem, but I was indignant at Pafo 915. When I completed 0 before, it was Pafo 339, so it is better than that.
I couldn't break through. Some people said on Twitter that they would multiply by 10 9 </ sup> to find out how many 2s and 5s were included, and I couldn't understand that person's explanation. However, since it is a decimal number, 2 and 5 should be enough. 2.4 that appears in the input example, but of course if you multiply it by 10, it becomes an integer, but even if you multiply it by 1.25, it becomes an integer. In short, 2 2 </ sup> × 3 × 5 -1 </ sup>, so if you cancel even 5 -1 </ sup>, up to 2 -2 </ sup> Once you know this, find out what the power of 2 and 5 is for each A i </ sub>, and if the sum of the multipliers of 2 and 5 is 0 or more for each combination, it is an integer. The total number of combinations of 2 and 5 is not so large, and * O * ( N </ i> 2 </ sup>) is enough.
def conv(s):
if s.find('.') == -1:
s += '.'
s = s.rstrip('0')
t = len(s) - s.find('.') - 1
a = int(s.replace('.', ''))
if a == 0:
return (0, 0)
x, y = -t, -t
while a % 5 == 0:
x += 1
a //= 5
while a % 2 == 0:
y += 1
a //= 2
return (x, y)
N, *A = open(0).read().split()
N = int(N)
d = {}
for a in A:
t = conv(a)
d.setdefault(t, 0)
d[t] += 1
result = 0
xs = list(d.keys())
for i in range(len(xs)):
x, y = xs[i]
t = d[xs[i]]
if x >= 0 and y >= 0:
result += t * (t - 1) // 2
for j in range(i + 1, len(xs)):
m, n = xs[j]
if x + m >= 0 and y + n >= 0:
result += t * d[xs[j]]
print(result)
Recommended Posts