結果
| 問題 |
No.1252 数字根D
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-09 21:58:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 493 bytes |
| コンパイル時間 | 330 ms |
| コンパイル使用メモリ | 82,184 KB |
| 実行使用メモリ | 70,432 KB |
| 最終ジャッジ日時 | 2024-07-20 11:08:43 |
| 合計ジャッジ時間 | 1,661 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
ans = [0]*T
for t in range(T):
d, A, B = map(int, input().split())
a = A
fa = 0
while a>=d:
while a>0:
fa += a%d
a //= d
a = fa
fa = 0
n = B-A+1
if n<d-a:
ans[t] = (a+(a+B-A))*(B-A+1)//2
continue
ans[t] += (a+(d-1))*(d-a)//2
cyc, mod = divmod(B-A+1-(d-a),d-1)
ans[t] += d*(d-1)//2*cyc+mod*(mod+1)//2
print(*ans, sep='\n')