結果
| 問題 |
No.1252 数字根D
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-09 23:05:05 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 721 bytes |
| コンパイル時間 | 95 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 17,564 KB |
| 最終ジャッジ日時 | 2024-07-20 13:56:38 |
| 合計ジャッジ時間 | 3,774 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 TLE * 1 -- * 12 |
ソースコード
t = int(input())
def digit_sum(x, d):
while x >= d:
tmp = 0
while x > 0:
tmp += x % d
x //= d
x = tmp
return x
for _ in range(t):
d, a, b = map(int, input().split())
left = digit_sum(a, d)
right = digit_sum(b, d)
# one_cycle = (d - 1) * d // 2
# cycle_len = d - 1
n = b - a + 1
# ds = digit_sum(a, d)
ans = 0
# ans = n // cycle_len * one_cycle
# head = one_cycle - (left - 1) * left // 2 if left != 1 else 0
# tail = right * (right + 1) // 2 if right < d - 1 else 0
for i in range(n):
ans += left
left += 1
if left == d:
left = 1
#print(ans + head + tail)
print(ans)