結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー sotanishysotanishy
提出日時 2021-07-31 00:06:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,048 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,700 KB
実行使用メモリ 54,704 KB
最終ジャッジ日時 2024-09-21 17:33:31
合計ジャッジ時間 3,855 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys
input = sys.stdin.readline

mod = 10**9 + 7
N = int(input())
c = [0] + list(map(int, input().split()))
for d in range(1, 10):
    if c[d] == N:
        print(d * (pow(10, N, mod) - 1) * pow(9, mod-2, mod) % mod)
        exit()
ans = 1
total = sum(d * c[d] for d in range(1, 10))
if c[2] + c[4] + c[6] + c[8] == N:
    ans *= 2
if c[4] + c[8] == N:
    ans *= 2
if total % 3 == 0:
    ans *= 3
if total % 9 == 0:
    ans *= 3

# check divisibility by 7
s = t = 0
for d in range(1, 10):
    s += d * (pow(10, c[d], 7) - 1) * pow(2, 5, 7) * pow(10, t, 7) % 7
    t += c[d]
if s % 7 == 0:
    ans *= 7

# check divisibility by 27
s = 0
t = ''
for d in range(1, 10):
    q, r = divmod(c[d], 3)
    s += d * 111 * q
    t += str(d) * r
for i in range(0, len(t), 3):
    s += int(t[i:i+3])
if s % 27 == 0:
    ans *= 3

for i in range(1, 9):
    for j in range(i + 1, 10):
        if c[i] > 0 and c[j] > 0:
            a = 10 * j + i
            b = 10 * i + j
            d = a - b
            ans = gcd(ans, d)
print(ans)
0