Интересная вещь, у меня этот код:
import psyco
psyco.full()
import sys
from cStringIO import StringIO
import gc; gc.disable()
fin = StringIO(sys.stdin.read())
fout = StringIO()
rinput = fin.readline
routput = fout.write
#rinput = sys.stdin.readline
#routput = sys.stdout.write
#from math import log
cache = []
def fillCache(maxVal):
curPowVal = 5
while curPowVal <= maxVal:
cache.append(curPowVal)
curPowVal *= 5
def main():
vals = []
fillCache(1000000000)
for i in xrange(int(rinput())):
vals.append(int(rinput()))
#val = int(rinput())
#print sum([val // divisor for divisor in cache])
for val in vals:
print sum([val // divisor for divisor in cache])#[:int(log(val, 5)) + 1]])
main()
работает быстрее на 2 десятых, чем:
import psyco
psyco.full()
import sys
from cStringIO import StringIO
import gc; gc.disable()
fin = StringIO(sys.stdin.read())
fout = StringIO()
rinput = fin.readline
routput = fout.write
#rinput = sys.stdin.readline
#routput = sys.stdout.write
#from math import log
cache = []
def fillCache(maxVal):
curPowVal = 5
while curPowVal <= maxVal:
cache.append(curPowVal)
curPowVal *= 5
def main():
#vals = []
fillCache(1000000000)
for i in xrange(int(rinput())):
#vals.append(int(rinput()))
val = int(rinput())
print sum([val // divisor for divisor in cache])
#for val in vals:
#print sum([val // divisor for divisor in cache])#[:int(log(val, 5)) + 1]])
main()