結果

問題 No.1252 数字根D
ユーザー Kou0406
提出日時 2025-02-05 10:53:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 472 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 58,624 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-02-05 10:53:04
合計ジャッジ時間 2,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
main.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d%d%d",&d,&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<iostream>
#include<cassert>
#define rep(i,n) for(i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int t,d,a,b;

ll f(int d,int a){
    if(a<0)return 0;
    ll ans=0,base=(ll)d*(d-1)/2;
    ans+=(a/(d-1))*base;
    d=a%(d-1);
    return ans+(ll)d*(d+1)/2;
}

int main(){
    int i,j;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d%d",&d,&a,&b);
        printf("%lld\n",f(d,b)-f(d,a-1));
    }
    return 0;
}
0