You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
481 B
20 lines
481 B
#!/usr/bin/env python3
|
|
|
|
from sys import argv
|
|
|
|
i = open(argv[1]).read().split("\n")
|
|
a = int(i[0].strip())
|
|
b = [int(x) if x != "x" else None for x in i[1].strip().split(",")]
|
|
|
|
e = sorted([(x, x-(a%x)) for x in b if x], key=lambda x: x[1])[0]
|
|
print(e[0]*e[1])
|
|
|
|
ma = [(i, x) for i, x in enumerate(b) if x]
|
|
ma.sort(key=lambda x: x[1], reverse=True)
|
|
s = ma[0][1]-ma[0][0]
|
|
m = ma[0][1]
|
|
for i, x in ma[1:]:
|
|
while x-(s%x) != (i%x if i%x != 0 else x):
|
|
s += m
|
|
m *= x
|
|
print(s)
|
|
|