結果

問題 No.1252 数字根D
ユーザー yuji9511yuji9511
提出日時 2020-10-09 23:07:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,132 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 197,672 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-27 19:32:23
合計ジャッジ時間 5,690 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 238 ms
4,380 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    ll d,A,B;
    cin >> d >> A >> B;
    ll n = B - A + 1;
    ll sum = A;
    while(true){
        ll tmp = sum;
        ll r = 0;
        while(tmp > 0){
            r += tmp % d;
            tmp /= d;
        }
        sum = r;
        if(sum < d) break;
    }
    ll v1 = d * (d-1) / 2;
    ll ans = v1 * (n / (d-1));
    rep(i,0,(n % (d-1))){
        ans += (sum-1 + i) % (d-1) + 1;
    }
    print(ans);


}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll T;
    cin >> T;
    while(T--) solve();
}
0