AtCoder Beginner Contest 174 C - Repsept【Python】
https://atcoder.jp/contests/abc174/tasks/abc174_c
AtCoder ProblemsでDifficulty: 902、Solve Probability: 21%でした。
解けませんでした。
mod K後の値で考えると、同じ値が出るとループになり、そうでない場合は、K項目までには0が出てくるはずなのでK回探索すれば良いということのようです。
K = int(input()) a = [-1] * (10 ** 6 + 1) a[1] = 7 % K for i in range(2, K + 1): a[i] = (a[i-1] * 10 + 7) % K for i in range(1, K + 1): if a[i] == 0: print(i) exit() print(-1)