結果

問題 No.1252 数字根D
ユーザー karinohitokarinohito
提出日時 2023-10-02 15:50:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 198,460 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-02 15:50:39
合計ジャッジ時間 3,107 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#include<time.h>
using namespace std;

using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;

bool DEB = 0;

ll arithsum(ll a,ll b,ll d=1){
    ll len=(b-a+1);
    return (a+b)*len/2;
}

void solve(){
    ll D,A,B;
    cin>>D>>A>>B;
    if(A==0&&B==0){
        cout<<0<<endl;
        return;
    }
    A=max(1ll,A);
    ll res=0;
    ll len=(B-A+1);
    res=(len/(D-1))*arithsum(1,D-1);
    B-=(len/(D-1))*(D-1);
    if(B<A){
        cout<<res<<endl;
        return;
    }
    //cout<<A<<" "<<B<<endl;
    A%=(D-1);
    if(A==0)A+=(D-1);
    B%=(D-1);
    if(B==0)B+=(D-1);
    //cout<<A<<" "<<B<<endl;
    if(A<=B){
        res+=arithsum(A,B);
    }
    else{
        res+=arithsum(A,D-1)+arithsum(1,B);
    }
    cout<<res<<endl;
    return;
}

int main() {
    
    ll T;
    cin>>T;
    rep(t,T)solve();

}
0