結果
問題 | No.1252 数字根D |
ユーザー |
![]() |
提出日時 | 2020-10-09 22:23:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,094 bytes |
コンパイル時間 | 1,524 ms |
コンパイル使用メモリ | 166,104 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-20 12:26:46 |
合計ジャッジ時間 | 2,248 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 WA * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; ll calc(ll d, ll x){ if(x < d) return x; ll p = 1; while(p<x){ p *= d; } ll ret = 0; while(p>0){ ret += x/p; x%=p; p/=d; } return calc(d, ret); } ll solve(ll d, ll A, ll B){ ll ret = 0; { ll n = B - (A-1); ll a = calc(d, A); ll x = d-1-(a-1); if(B < a+x){ ll b = calc(d, B); ret += n * (a+b) / 2; return ret; }else{ ll b = d-1; ret += x * (a+b) / 2; } A+= x; } { ll n = B - (A-1); ll x = n / (d-1); ret += x * (d-1) * (1 + d-1) / 2; A += x * (d-1); } { ll n = B - (A-1); ret += n * (1 + n) / 2; } return ret; } int main(){ int T; cin >> T; rep(t,T){ ll d, A, B; cin >> d >> A >> B; cout << solve(d, A, B) << endl; } return 0; }