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.

27 satır
586B

  1. import sys
  2. from itertools import count
  3. import toolkit
  4. text = sys.stdin.read()
  5. tid, string = text.split()
  6. tid = int(tid)
  7. found = [
  8. next((tid + i, val) for i in count() if (tid + i) % val == 0)
  9. for val in [int(v) for v in string.split(',') if v != 'x']
  10. ]
  11. a, b = min(found)
  12. print((a - tid) * b)
  13. args = [(i, int(val)) for i, val in enumerate(string.split(',')) if val != 'x']
  14. (last, step), *tail = args
  15. for offset, value in tail:
  16. i = next(i for i in count() if (last + i * step + offset) % value == 0)
  17. last += i * step
  18. step = toolkit.lcm(step, value)
  19. print(last)