結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー nok0nok0
提出日時 2021-07-30 23:04:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 53,748 KB
最終ジャッジ日時 2023-10-21 16:17:52
合計ジャッジ時間 4,402 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,744 KB
testcase_01 AC 38 ms
53,744 KB
testcase_02 AC 36 ms
53,680 KB
testcase_03 AC 38 ms
53,744 KB
testcase_04 AC 40 ms
53,744 KB
testcase_05 AC 38 ms
53,748 KB
testcase_06 AC 37 ms
53,744 KB
testcase_07 AC 38 ms
53,744 KB
testcase_08 AC 38 ms
53,744 KB
testcase_09 AC 36 ms
53,744 KB
testcase_10 AC 38 ms
53,744 KB
testcase_11 AC 38 ms
53,744 KB
testcase_12 AC 36 ms
53,744 KB
testcase_13 AC 36 ms
53,748 KB
testcase_14 AC 36 ms
53,744 KB
testcase_15 AC 36 ms
53,744 KB
testcase_16 AC 38 ms
53,744 KB
testcase_17 AC 39 ms
53,744 KB
testcase_18 AC 38 ms
53,748 KB
testcase_19 AC 37 ms
53,744 KB
testcase_20 AC 36 ms
53,744 KB
testcase_21 AC 36 ms
53,744 KB
testcase_22 AC 38 ms
53,744 KB
testcase_23 AC 38 ms
53,744 KB
testcase_24 AC 36 ms
53,744 KB
testcase_25 AC 38 ms
53,744 KB
testcase_26 AC 36 ms
53,744 KB
testcase_27 AC 37 ms
53,744 KB
testcase_28 AC 39 ms
53,744 KB
testcase_29 AC 38 ms
53,748 KB
testcase_30 AC 38 ms
53,744 KB
testcase_31 AC 38 ms
53,748 KB
testcase_32 AC 40 ms
53,744 KB
testcase_33 AC 38 ms
53,744 KB
testcase_34 AC 39 ms
53,744 KB
testcase_35 AC 35 ms
53,744 KB
testcase_36 AC 36 ms
53,744 KB
testcase_37 AC 36 ms
53,744 KB
testcase_38 AC 37 ms
53,744 KB
testcase_39 AC 38 ms
53,744 KB
testcase_40 AC 38 ms
53,744 KB
testcase_41 AC 37 ms
53,744 KB
testcase_42 AC 36 ms
53,744 KB
testcase_43 AC 36 ms
53,744 KB
testcase_44 AC 37 ms
53,744 KB
testcase_45 AC 38 ms
53,744 KB
testcase_46 AC 37 ms
53,744 KB
testcase_47 AC 38 ms
53,744 KB
testcase_48 AC 37 ms
53,744 KB
testcase_49 AC 38 ms
53,744 KB
testcase_50 AC 38 ms
53,744 KB
testcase_51 AC 38 ms
53,744 KB
testcase_52 AC 38 ms
53,744 KB
testcase_53 AC 38 ms
53,744 KB
testcase_54 AC 37 ms
53,744 KB
testcase_55 AC 38 ms
53,744 KB
testcase_56 AC 37 ms
53,744 KB
testcase_57 AC 37 ms
53,744 KB
testcase_58 AC 37 ms
53,744 KB
testcase_59 AC 35 ms
53,684 KB
testcase_60 AC 36 ms
53,680 KB
testcase_61 AC 37 ms
53,680 KB
testcase_62 AC 37 ms
53,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0