結果
| 問題 |
No.1252 数字根D
|
| コンテスト | |
| ユーザー |
fastmath
|
| 提出日時 | 2020-10-09 23:21:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,471 bytes |
| コンパイル時間 | 2,205 ms |
| コンパイル使用メモリ | 193,132 KB |
| 最終ジャッジ日時 | 2025-01-15 05:48:56 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout.setf(ios::fixed); cout.precision(20);
#endif
auto mod = [&] (int n, int m) {
if (n % m == 0)
return m;
else
return n % m;
};
int t;
cin >> t;
auto f = [&] (int n, int d) {
int ans = 0;
while (n) {
ans += n % d;
n /= d;
}
return ans;
};
auto sum = [&] (int n) {
return n * (n + 1) / 2;
};
auto solve = [&] (int d, int n) {
if (n <= 0)
return 0ll;
int c = n/(d-1);
int rem = n % (d - 1);
return c * sum(d - 1) + sum(rem);
/*
int ans = 0;
for (int i = 1; i <= n; ++i) {
ans += mod(i, d - 1);
}
return ans;
*/
};
while (t--) {
int d, l, r;
cin >> d >> l >> r;
cout << solve(d, r) - solve(d, l - 1) << endl;
}
}
fastmath