結果
| 問題 |
No.752 mod数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-19 11:26:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,619 bytes |
| コンパイル時間 | 1,428 ms |
| コンパイル使用メモリ | 123,344 KB |
| 最終ジャッジ日時 | 2025-01-10 13:04:33 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 TLE * 1 |
| other | AC * 16 TLE * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:66:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
66 | scanf("%lld %lld", &P, &Q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:72:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
72 | ll l, r; scanf("%lld %lld", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
long double PI = acos(-1);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll sum[10000001];
ll P, Q;
ll solve(ll x) {
ll res = P * x;
if (x <= 10000000) res -= sum[x];
else {
res -= sum[10000000];
for (ll i = 1;; i++) {
ll lf = min(P / (i + 1) + 1, 10000001LL);
ll rg = max(P / i, x);
if (lf > rg) continue;
if (rg <= 10000000) break;
res -= i * (lf + rg) * (rg - lf + 1) / 2;
}
}
return res;
}
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
scanf("%lld %lld", &P, &Q);
for (ll i = 1; i <= 10000000; i++) {
sum[i] = sum[i - 1];
sum[i] += P / i * i;
}
while (Q--) {
ll l, r; scanf("%lld %lld", &l, &r);
l--;
ll res = solve(r);
if (l) res -= solve(l);
printf("%lld\n", res);
}
return 0;
}