-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWithoutStatement.py
55 lines (47 loc) · 1.19 KB
/
WithoutStatement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# this one is an exercise program from HackerEarth
# Unfortunately someone has come and eaten the problem statement. Are you good enough to solve it without the statement?
# Input
# The first line contains T denoting the number of test cases. The next T lines describe test cases and contain two integers each: N and M.
# Output
# For each test case output one integer - answer for the question.
# Constraints
# T <= 1000
# 1 <= N, M <= 109
# Note: N, M <= 1000 for 30% of the test
# sample inputs:
# 6
# 28 1
# 39 1
# 90 1
# 15 2
# 123 2
# 114514 1919
# sample outputs:
# 68
# 90
# 81
# 40
# 17
# 16
# Solution:
cases = int(input())
result_arr = []
for i in range(cases):
current_num, cases = map(int, input().split(' '))
j = cases
while j > 0:
# this conditions are based on Guillermo_Casanova's solution
if current_num == 1:
break
elif current_num == 4:
if j >= 8:
j = (j % 8)
continue
else:
current_num = 16
else:
current_num = sum(int(var)**2 for var in str(current_num))
j -= 1
result_arr.append(current_num)
for elem in result_arr:
print(elem)