結果
| 問題 |
No.493 とても長い数列と文字列(Long Long Sequence and a String)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:53:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,529 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,704 KB |
| 実行使用メモリ | 85,492 KB |
| 最終ジャッジ日時 | 2025-06-12 13:54:31 |
| 合計ジャッジ時間 | 4,300 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 TLE * 1 -- * 109 |
ソースコード
import sys
import math
MOD = 10**9 + 7
def compute_len(k):
if k == 0:
return 0
if k == 1:
return 1
total = 1 << (k-1)
sum_part = 0
for d in range(1, 20):
a_d = math.ceil(10**((d-1)/2))
b_d = math.isqrt(10**d - 1)
lower = max(2, a_d)
upper = min(k, b_d)
if lower > upper:
continue
exponent = k - upper
count = upper - lower + 1
term = ((1 << count) - 1) << exponent
sum_part += d * term
total += sum_part
return total
def get_digit(k, pos):
while True:
if k == 1:
return 1
len_prev = compute_len(k-1)
s_k = len(str(k*k))
if pos > len_prev + s_k:
pos -= (len_prev + s_k)
k -= 1
elif pos > len_prev:
num_str = str(k*k)
return int(num_str[pos - len_prev - 1])
else:
k -= 1
def main():
K, L, R = map(int, sys.stdin.readline().split())
if K >= 60:
len_K = None
else:
len_K = compute_len(K)
if len_K < R:
print(-1)
return
sum_total = 0
product_total = 1
for pos in range(L, R+1):
digit = get_digit(K, pos)
if digit == 0:
sum_total += 10
product_total = product_total * 10 % MOD
else:
sum_total += digit
product_total = product_total * digit % MOD
print(sum_total, product_total)
if __name__ == "__main__":
main()
gew1fw