結果
問題 | No.1252 数字根D |
ユーザー |
|
提出日時 | 2020-10-10 00:34:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 534 bytes |
コンパイル時間 | 1,464 ms |
コンパイル使用メモリ | 165,648 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 15:00:34 |
合計ジャッジ時間 | 2,116 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr char newl = '\n'; ll calc(ll n, ll d) { if (n <= 0) return 0; ll ans = (d - 1) * d / 2 * (n / (d - 1)); ll rest = n % (d - 1); ans += (rest + 1) * rest / 2; return ans; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; for (int loop = 0; loop < t; loop++) { ll d, a, b; cin >> d >> a >> b; cout << calc(b, d) - calc(a - 1, d) << newl; } return 0; }