結果
| 問題 |
No.752 mod数列
|
| コンテスト | |
| ユーザー |
rsk0315
|
| 提出日時 | 2020-04-23 19:10:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 1,047 bytes |
| コンパイル時間 | 893 ms |
| コンパイル使用メモリ | 60,384 KB |
| 最終ジャッジ日時 | 2025-01-09 22:51:19 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%jd %d", &p, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%jd %jd", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <vector>
int main() {
intmax_t p;
int q;
scanf("%jd %d", &p, &q);
std::vector<intmax_t> d{0};
{
std::vector<intmax_t> tmp;
for (intmax_t i = 1; i*i <= p; ++i) {
d.push_back(i);
if (i*i < p) tmp.push_back(p/i);
}
d.insert(d.end(), tmp.rbegin(), tmp.rend());
}
std::vector<intmax_t> s{0};
for (size_t i = 1; i < d.size(); ++i) {
intmax_t dl = d[i-1]+1;
intmax_t dr = d[i];
intmax_t sum = ((p % dl) + (p % dr)) * (dr-dl+1) / 2;
s.push_back(sum);
}
s.insert(s.begin(), 0);
for (size_t i = 1; i < s.size(); ++i) s[i] += s[i-1];
auto f = [&](intmax_t r) -> intmax_t {
if (r == 0) return 0;
auto it = std::upper_bound(d.begin(), d.end(), r);
size_t j = it - d.begin();
intmax_t dl = it[-1]+1;
intmax_t dr = r;
return s[j] + ((p % dl) + (p % dr)) * (dr-dl+1) / 2;
};
for (int i = 0; i < q; ++i) {
intmax_t l, r;
scanf("%jd %jd", &l, &r);
printf("%jd\n", f(r)-f(l-1));
}
}
rsk0315