Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@haje01
Created December 22, 2014 11:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haje01/6f384a54dc23d0f20380 to your computer and use it in GitHub Desktop.
Save haje01/6f384a54dc23d0f20380 to your computer and use it in GitHub Desktop.
def gen_data():
a = 1983
po = pow(2, 32)
while True:
yield a % 10000 + 1
a = (a * 214013 + 2531011) % po
def do_case(k, n):
head = gen_data().next
tail = gen_data().next
cnt = hi = 0
csum = head()
while True:
if csum <= k:
if csum == k:
cnt += 1
hi += 1
if hi == n:
break
csum += head()
else:
csum -= tail()
return cnt
if __name__ == "__main__":
c = int(raw_input())
for i in range(c):
k, n = [int(v) for v in raw_input().split()]
print do_case(k, n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment