Submission #26018285


Source Code Expand

n, k = list(map(int, input().split()))

def f(n):
    y = sum(map(int, list(str(n))))
    return (n + y) % (10 ** 5)

def solve(n):
    cyc = 0
    hist = set()
    x = n
    pre = -1
    while True:
        x = f(x)
        cyc += 1
        if cyc == k:
            res = [n]
            for _ in range(cyc):
                res.append(f(res[-1]))
            return 0, 10 ** 5, res
        if x in hist:
            pre = x
            break
        hist.add(x)

    hist = [pre]
    cnt = 0
    while n != pre:
        n = f(n)
        cnt += 1
        hist.append(f(hist[-1]))
    return cnt, cyc, hist

start, cyc, hist = solve(n)
i = (k - start) % (cyc - start)
# print(i)
ans = hist[0]
for _ in range(i):
    ans = f(ans)

print(ans)

Submission Info

Submission Time
Task 058 - Original Calculator(★4)
User wakameTech
Language PyPy3 (7.3.0)
Score 4
Code Size 779 Byte
Status AC
Exec Time 85 ms
Memory 74636 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 4 / 4
Status
AC × 3
AC × 28
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 03_fixed_01.txt, 03_fixed_02.txt, 03_fixed_03.txt, 03_fixed_04.txt, 03_fixed_05.txt, 03_fixed_06.txt, 04_special_01.txt, 04_special_02.txt, 04_special_03.txt, 04_special_04.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 68 ms 61916 KiB
01_sample_02.txt AC 42 ms 61820 KiB
01_sample_03.txt AC 73 ms 74236 KiB
02_random_01.txt AC 75 ms 74404 KiB
02_random_02.txt AC 65 ms 73704 KiB
02_random_03.txt AC 84 ms 74532 KiB
02_random_04.txt AC 76 ms 74516 KiB
02_random_05.txt AC 68 ms 73860 KiB
02_random_06.txt AC 69 ms 74220 KiB
02_random_07.txt AC 83 ms 74340 KiB
02_random_08.txt AC 71 ms 74248 KiB
02_random_09.txt AC 72 ms 74176 KiB
02_random_10.txt AC 81 ms 74636 KiB
02_random_11.txt AC 71 ms 74112 KiB
02_random_12.txt AC 66 ms 74000 KiB
02_random_13.txt AC 68 ms 73676 KiB
02_random_14.txt AC 73 ms 74028 KiB
02_random_15.txt AC 71 ms 73868 KiB
03_fixed_01.txt AC 79 ms 74412 KiB
03_fixed_02.txt AC 79 ms 74396 KiB
03_fixed_03.txt AC 85 ms 74356 KiB
03_fixed_04.txt AC 70 ms 74044 KiB
03_fixed_05.txt AC 49 ms 62048 KiB
03_fixed_06.txt AC 49 ms 62112 KiB
04_special_01.txt AC 82 ms 74044 KiB
04_special_02.txt AC 77 ms 74524 KiB
04_special_03.txt AC 78 ms 74444 KiB
04_special_04.txt AC 70 ms 74052 KiB