Участник:KislinskiyVadim/PATHEADS python

Материал из DISCOPAL
Перейти к: навигация, поиск

https://www.spoj.com/problems/PATHEADS/ второй питон, компилятор PYPY

import array
n = int(raw_input())
a = array.array('l', (0 for _ in xrange(1000001)))
cnt = array.array('l', (0 for _ in xrange(1000001)))
res = array.array('l', (0 for _ in xrange(1000001)))
max_ = -1
for i in xrange(n):
    a[i] = int(raw_input())
    max_ = max(a[i], max_)
    cnt[a[i]] += 1
 
for i in xrange(n):
    if (a[i] > 1) and (cnt[a[i]]):
        for j in xrange(a[i], max_ + 1, a[i]):
            res[j] += cnt[a[i]]
        cnt[a[i]] = 0
 
for i in xrange(n):
    print res[a[i]] - 1 + cnt[1]