QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142748 | #6188. Elliptic Curve Problem | SanguineChameleon | AC ✓ | 2123ms | 64056kb | C++20 | 1.7kb | 2023-08-19 20:01:13 | 2023-08-19 20:01:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
long long P, delta;
long long cur_x, cur_y;
__int128 sum;
bool inside(long long x, long long y) {
return (((__int128)x * x + delta) / P) < y;
}
void build(long long a, long long b, long long c, long long d) {
long long e = a + c;
long long f = b + d;
if (cur_x < e || cur_y < f) {
return;
}
if (inside(cur_x - e, cur_y - f)) {
build(a, b, e, f);
}
else if ((__int128)P * d >= (__int128)2 * (cur_x - e) * c) {
return;
}
if (cur_x < e || cur_y < f) {
return;
}
if (inside(cur_x - e, cur_y - f)) {
long long lt = 1;
long long rt = min(cur_x / e, cur_y / f);
while (lt <= rt) {
long long mt = (lt + rt) / 2;
if (inside(cur_x - e * mt, cur_y - f * mt)) {
lt = mt + 1;
}
else {
rt = mt - 1;
}
}
long long k = rt;
long long nxt_x = cur_x - e * k;
long long nxt_y = cur_y - f * k;
sum += (__int128(cur_y + nxt_y) * (cur_x - nxt_x) - (cur_y + nxt_y + cur_x - nxt_x + k)) / 2 + cur_y;
cur_x = nxt_x;
cur_y = nxt_y;
}
if (cur_x < c || cur_y < d) {
return;
}
if (inside(cur_x - c, cur_y - d)) {
build(e, f, c, d);
}
}
void calc() {
cur_x = (P - 1) / 2;
cur_y = ((__int128)cur_x * cur_x + delta) / P + 1;
sum = 0;
build(0, 1, 1, 0);
}
void just_do_it() {
long long L, R;
cin >> P >> L >> R;
delta = P - L;
calc();
__int128 sum1 = sum;
delta = P - R - 1;
calc();
__int128 sum2 = sum;
long long res = sum1 - sum2;
cout << res;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3516kb
input:
11 3 8
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 91ms
memory: 7800kb
input:
998244353 11451400 919810000
output:
454174074
result:
ok 1 number(s): "454174074"
Test #3:
score: 0
Accepted
time: 2082ms
memory: 59472kb
input:
96311898227 25437319919 55129361817
output:
14846091352
result:
ok 1 number(s): "14846091352"
Test #4:
score: 0
Accepted
time: 2024ms
memory: 64056kb
input:
93361455259 23166562299 23393760915
output:
113606479
result:
ok 1 number(s): "113606479"
Test #5:
score: 0
Accepted
time: 2074ms
memory: 37768kb
input:
95670332497 15858139735 18812394512
output:
1477133816
result:
ok 1 number(s): "1477133816"
Test #6:
score: 0
Accepted
time: 2042ms
memory: 50260kb
input:
94221254297 78612110347 90331192055
output:
5859602618
result:
ok 1 number(s): "5859602618"
Test #7:
score: 0
Accepted
time: 2016ms
memory: 48464kb
input:
92756073587 18915851957 32881684894
output:
6982950261
result:
ok 1 number(s): "6982950261"
Test #8:
score: 0
Accepted
time: 2027ms
memory: 40644kb
input:
93651628361 3508055978 32362767220
output:
14427310592
result:
ok 1 number(s): "14427310592"
Test #9:
score: 0
Accepted
time: 2074ms
memory: 32480kb
input:
97506758381 48269906857 58513759044
output:
5121898347
result:
ok 1 number(s): "5121898347"
Test #10:
score: 0
Accepted
time: 2123ms
memory: 45192kb
input:
99954950231 20710324571 44996152988
output:
12142951150
result:
ok 1 number(s): "12142951150"
Test #11:
score: 0
Accepted
time: 2104ms
memory: 47924kb
input:
99367158071 38747300608 85189731653
output:
23221174712
result:
ok 1 number(s): "23221174712"
Test #12:
score: 0
Accepted
time: 2114ms
memory: 33672kb
input:
99936206351 6721710119 93710740278
output:
43494512281
result:
ok 1 number(s): "43494512281"