結果

問題 No.1252 数字根D
ユーザー kenta255kenta255
提出日時 2020-10-09 23:09:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 1,945 ms
コンパイル使用メモリ 198,188 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 19:33:03
合計ジャッジ時間 2,610 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}

pair<ll,ll> f(ll A,ll d){
	if(A<0)return {0,0};
	ll x = (A/(d-1));
	ll res = d * (d-1) / 2 * x;
	x *= (d-1);
	return {res,(A-x+1)*(A-x) / 2};
}

int main(){

	ll T;
	cin >> T;
	FORR(t,0,T){
		ll d,A,B;
		cin >> d >> A >> B;
		ll ans=0;
		auto b = f(B,d),a = f(A-1,d);
		ans = b.first - a.first - a.second + b.second;
		cout << ans << endl;
	}

}
0