結果

問題 No.1580 I like Logarithm!
コンテスト
ユーザー 👑 rin204
提出日時 2022-01-18 03:00:31
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 30 ms / 2,000 ms
+ 958µs
コード長 390 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 63 ms
コンパイル使用メモリ 81,372 KB
実行使用メモリ 70,232 KB
最終ジャッジ日時 2026-09-28 15:09:34
合計ジャッジ時間 4,388 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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