Skip to content

Instantly share code, notes, and snippets.

@binhngoc17
Created November 19, 2014 14:42
Show Gist options
  • Save binhngoc17/971388ad442f4d9e4a22 to your computer and use it in GitHub Desktop.
Save binhngoc17/971388ad442f4d9e4a22 to your computer and use it in GitHub Desktop.
Count ending number
import sys
import pprint
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
str_val = test.replace('\n', '')
n,p = [int(k) for k in str_val.split(' ')]
res = {}
for i in range(0, 10):
res[i] = 0
if n > 10:
prev = n - 10
else:
prev = n
res[prev] = res[prev] + 1
i = 0
while i < p:
val = prev * n
if val >= 10:
val = val % 10
res[val] = res[val] + 1
prev = val
i = i + 1
print ', '.join(['{}: {}'.format(k, res[k]) for k in sorted(res.keys())])
test_cases.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment