Created
November 19, 2014 14:42
-
-
Save binhngoc17/971388ad442f4d9e4a22 to your computer and use it in GitHub Desktop.
Count ending number
This file contains hidden or 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 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