QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743280 | #9597. Grade 2 | lonelywolf# | TL | 19ms | 3816kb | C++17 | 1.8kb | 2024-11-13 18:49:20 | 2024-11-13 18:49:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, n;
cin >> x >> n;
if (x % 2 == 0) {
while (n--) {
int l, r;
cin >> l >> r;
cout << 0 << "\n";
}
return 0;
}
if (x == 1) {
while (n--) {
int l, r;
cin >> l >> r;
cout << r - l + 1 << "\n";
}
return 0;
}
vector<int> t;
int b = 0;
int f = 1;
int len = 0;
auto check = [&](int k) {
vector<int> tt;
int ff = 1, bb = 0;
while (tt.size() < k) {
if (gcd((ff * x) ^ x, x) == 1) {
if (bb == 0) {
bb = ff;
} else {
tt.push_back(ff - bb);
}
}
ff++;
}
int T = tt.back();
for (auto q : tt) {
q += bb;
if (gcd(((q + T) * x) ^ x, x) != 1) {
return false;
}
}
return true;
};
for (int i = x - 1; true; i += 2) {
if (check(i)) {
len = i;
break;
}
}
while (t.size() < len) {
if (gcd((f * x) ^ x, x) == 1) {
if (b == 0) {
b = f;
} else {
t.push_back(f - b);
}
}
f++;
}
int T = t.back();
auto calc = [&](int a) {
if (a < b) {
return 0LL;
}
a -= b;
int ret = 1 + a / T * t.size();
a %= T;
int l = -1, r = t.size();
while (l + 1 != r) {
int m = (l + r) / 2;
if (t[m] <= a) {
l = m;
} else {
r = m;
}
}
ret += l + 1;
return ret;
};
while (n--) {
int l, r;
cin >> l >> r;
cout << calc(r) - calc(l - 1) << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
15 2 1 4 11 4514
output:
2 2252
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 19ms
memory: 3616kb
input:
500696 100000 110442401300 646889080214 337192 670162015551 508011001649 508011014425 94418501628 94418501634 824168677375 824168677376 732815842309 795402573302 353241304050 846773277757 622033633276 622033633284 760381702139 760381702143 207714 795408271057 382792 952061527685 686173 331215904334 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #3:
score: 0
Accepted
time: 11ms
memory: 3560kb
input:
465262 100000 119442423888 249533375982 528365238401 528365275157 654839906300 654839906303 135820863700 135820967840 336231 918143221477 568175915485 568176067832 993015103483 993015103488 951474 444595379179 298623434750 298623434751 257961 410491919396 996297715292 996297994388 17765498878 177654...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #4:
score: 0
Accepted
time: 15ms
memory: 3552kb
input:
599394 100000 683408 868635908987 347999512025 347999739145 740945 377178907084 399211757563 399211757568 766968 548821086083 630762 702128377806 756554924031 756554924036 904713771313 904714518208 17026878789 17027129255 11601638470 206412869961 253365321722 253365321730 785476956554 785477402085 2...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #5:
score: -100
Time Limit Exceeded
input:
255255 100000 693776785134 693776920782 174578728959 174578728960 109045569231 631173362385 470661333171 470661439492 401883 183360880923 436203696728 436203931780 165055 339075075373 640081 299360395352 864237441330 864237509663 730335563579 730335652091 194265481215 194265481219 40664920117 406649...