結果

問題 No.1580 I like Logarithm!
ユーザー 👑 rin204
提出日時 2022-01-18 03:00:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 390 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 66,560 KB
最終ジャッジ日時 2024-11-23 13:11:57
合計ジャッジ時間 3,954 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

a = int(input())
B = input()
l = len(B)
if l == 1:
    print(0)
    exit()
ans = 0
times = a - 1
for i in range(l - 1):
    ans += i * times
    ans %= MOD
    times *= a
    times %= MOD

tot = 0
times = 1
for b in B[::-1]:
    tot += times * int(b)
    tot %= MOD
    times *= a
    times %= MOD

ans += (tot - pow(a, l - 1, MOD) + 1) * (l - 1) % MOD
print(ans % MOD)

0