結果
| 問題 |
No.752 mod数列
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-06-18 08:31:49 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 1,412 bytes |
| コンパイル時間 | 526 ms |
| コンパイル使用メモリ | 33,152 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 07:44:11 |
| 合計ジャッジ時間 | 3,923 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.c: In function 'in':
main.c:10:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
10 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:18:24: note: in expansion of macro 'gc'
18 | int n = 0, c = gc();
| ^~
main.c: In function 'out':
main.c:11:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
11 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:28:17: note: in expansion of macro 'pc'
28 | if (!n) pc('0');
| ^~
ソースコード
// yukicoder: No.752 mod数列
// 2019.6.17 bal4u
#include <stdio.h>
#include <math.h>
typedef long long ll;
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
void out(ll n) // 非負整数の表示(出力)
{
int i;
char b[50];
if (!n) pc('0');
else {
i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
while (i--) pc(b[i]);
}
pc('\n');
}
int sa[31650];
ll s[31650];
int P;
ll sum(int l, int r, int d) {
if (l > r) return 0;
return ((((P % r)<<1) + (ll)(r-l)*d)*(r-l+1)) >> 1;
}
int main()
{
int i, r, n, pl, pr, Q, L, R, M;
ll ans;
P = in(), Q = in();
r = (int)sqrt((double)P);
M = P/r;
for (i = 2; i <= M; i++) sa[i] = sa[i-1] + P % i;
n = P; for (i = 1; i < r; i++) {
int a = P % n, k = P/(i+1);
s[i+1] = s[i] + ((((a<<1) + (ll)(n-k-1)*i)*(n-k)) >> 1);
n = k;
}
while (Q--) {
L = in(), R = in(), pl = P/L, pr = P/R;
if (pr == 0) pr = 1;
if (R <= M) ans = sa[R] - sa[L-1];
else if (L <= M) {
ans = sa[M] - sa[L-1] + (s[r]-s[pr]) - sum(R+1, P/pr, pr);
}
else if (L <= P) {
ans = s[pl]-s[pr] + sum(L, P/pl, pl) - sum(R+1, P/pr, pr);
}
if (L > P) ans = (ll)P * (R-L+1);
else if (R > P) ans += (ll)P * (R-P);
out(ans);
}
return 0;
}
bal4u