結果
| 問題 | No.1252 数字根D | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-10-02 15:50:35 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 2,000 ms | 
| コード長 | 1,087 bytes | 
| コンパイル時間 | 1,734 ms | 
| コンパイル使用メモリ | 192,456 KB | 
| 最終ジャッジ日時 | 2025-02-17 04:01:11 | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 14 | 
ソースコード
#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();
}
            
            
            
        