結果
問題 |
No.493 とても長い数列と文字列(Long Long Sequence and a String)
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:51:24 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,460 bytes |
コンパイル時間 | 210 ms |
コンパイル使用メモリ | 82,148 KB |
実行使用メモリ | 77,336 KB |
最終ジャッジ日時 | 2025-06-12 13:52:12 |
合計ジャッジ時間 | 3,919 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 TLE * 1 -- * 109 |
ソースコード
import math MOD = 10**9 + 7 def number_of_digits(k): return len(str(k * k)) def compute_len(n, max_limit=10**18): if n == 1: return 1 if (n - 1) > 60: pow_2 = max_limit + 1 else: pow_2 = 1 << (n - 1) if pow_2 > max_limit: pow_2 = max_limit + 1 if pow_2 > max_limit: return max_limit + 1 sum_terms = 0 for m in range(1, 20): lower = 10 ** (m - 1) upper = 10 ** m k_min = math.isqrt(lower) if k_min * k_min < lower: k_min += 1 k_max = math.isqrt(upper - 1) k_start = max(k_min, 2) k_end = min(k_max, n) if k_start > k_end: continue exponent_start = n - k_start + 1 exponent_end = n - k_end if exponent_start > 60: sum_terms = max_limit + 1 break pow_start = 1 << exponent_start pow_end = 0 if exponent_end < 0 else (1 << exponent_end) if exponent_end <= 60 else max_limit + 1 term = pow_start - pow_end contribution = m * term if contribution > max_limit - sum_terms: sum_terms = max_limit + 1 break else: sum_terms += contribution if sum_terms > max_limit: sum_terms = max_limit + 1 break total = pow_2 + sum_terms return total if total <= max_limit else max_limit + 1 def get_digit(n, pos): current_n = n while True: if current_n == 1: return '1' len_prev = compute_len(current_n - 1) d = number_of_digits(current_n) if pos <= len_prev: current_n -= 1 else: pos -= len_prev if pos <= d: s = str(current_n * current_n) return s[pos - 1] else: pos -= d current_n -= 1 def solve(): K, L, R = map(int, input().split()) max_len = compute_len(K) if max_len == 10**18 + 1: max_len = float('inf') if R > max_len: print(-1) return sum_val = 0 product_val = 1 for pos in range(L, R + 1): c = get_digit(K, pos) num = int(c) if num == 0: sum_val += 10 product_val = (product_val * 10) % MOD else: sum_val += num product_val = (product_val * num) % MOD print(sum_val, product_val) if __name__ == "__main__": solve()