結果
問題 |
No.1632 Sorting Integers (GCD of M)
|
ユーザー |
![]() |
提出日時 | 2021-07-30 23:04:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 841 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 82,076 KB |
実行使用メモリ | 54,348 KB |
最終ジャッジ日時 | 2024-09-21 17:32:19 |
合計ジャッジ時間 | 3,987 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 59 |
ソースコード
from math import gcd mod = 10 ** 9 + 7 n = int(input()) c = list(map(int, input().split())) g = 0 for i in range(9): for j in range(i + 1, 9): if c[i] and c[j]: g = gcd(g, 9 * (j - i)) def one_mod(n, mod): if n == 0: return 0 if n == 1: return 1 if n % 2 == 0: return one_mod(n // 2, mod) * (1 + pow(10, n // 2, mod)) return one_mod(n - 1, mod) + pow(10, n - 1, mod) res = 0 if g == 0: x = 0 for i in range(9): x *= pow(10, c[i], mod) x += (i + 1) * one_mod(c[i], mod) x %= mod print(x) exit() for k in range(1, g + 1): if g % k: continue x = 0 for i in range(9): x *= pow(10, c[i], k) x += (i + 1) * one_mod(c[i], k) x %= k if x == 0: res = k print(res % mod)