Created
April 18, 2015 03:36
-
-
Save LXZE/5d07b596f9bde567ed3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from fractions import gcd | |
def lcm(numbers): | |
return reduce(lambda x, y: (x*y)/gcd(x,y), numbers, 1) | |
f = open("B-large.in","r") | |
w = open("output_blarge.txt","w") | |
num = f.readline() | |
for i in range(0,int(num)): | |
barber,atN = [long(l) for l in f.readline().split()] | |
speed = [int(l) for l in f.readline().split()] | |
res = 1 | |
l = [] | |
for k,s in enumerate(speed): | |
l.append(k+1) | |
numLcm = lcm(speed) | |
t = 1 | |
while t<numLcm: | |
for iSpeed,s in enumerate(speed): | |
if t%s == 0: | |
l.append(iSpeed+1) | |
t+=1 | |
res = l[(atN%len(l))-1] | |
print("Case #{0}: {1} ".format(i+1,res)) | |
w.write("Case #{0}: {1}\n".format(i+1,res)) | |
w.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment