結果
問題 | No.493 とても長い数列と文字列(Long Long Sequence and a String) |
ユーザー | maspy |
提出日時 | 2020-04-01 03:11:09 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 31 ms / 800 ms |
コード長 | 1,352 bytes |
コンパイル時間 | 315 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-06-25 19:11:12 |
合計ジャッジ時間 | 6,256 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 115 |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10 ** 9 + 7 K, L, R = map(int, read().split()) sizes = [0] * 100 sums = [0] * 100 products = [1] * 100 for n in range(1, 100): num = str(n * n) s = 0 p = 1 for x in map(int, num): if not x: x = 10 s += x p *= x sizes[n] = sizes[n - 1] * 2 + len(num) sums[n] = sums[n - 1] * 2 + s products[n] = products[n - 1] ** 2 * p products[n] %= MOD def g(n, N): num = str(n * n)[:N] s = 0 p = 1 for x in map(int, num): if not x: x = 10 s += x p *= x return s, p def f(N): S = 0 P = 1 for level in range(99, 0, -1): if not N: return S, P if N < sizes[level]: level -= 1 continue N -= sizes[level] S += sums[level] P *= products[level] L = len(str((level + 1) ** 2)) if N <= L: s, p = g(level + 1, N) return S + s, P * p N -= L s, p = g(level + 1, L) S += s P *= p return S, P if K < 100 and R > sizes[K]: print(-1) exit() S1, P1 = f(R) S2, P2 = f(L - 1) S = S1 - S2 P = P1 * pow(P2, MOD - 2, MOD) % MOD print(S, P)