QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749241#12. SumI_be_wanna100 ✓31ms3728kbC++206.2kb2024-11-14 23:11:222024-11-14 23:11:22

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 23:11:22]
  • 评测
  • 测评结果:100
  • 用时:31ms
  • 内存:3728kb
  • [2024-11-14 23:11:22]
  • 提交

answer

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;

i64 n, r;
long double sqrtr;

tuple<i64, i64, i64> inverse(i64 &a, i64 &b, i64 &c) {
	return {-a * c, b * c, b * b - a * a * r};
}

i64 calc(i64 a, i64 b, i64 c, i64 n) {
	i64 g = __gcd(a, __gcd(b, c));
	a /= g, b /= g, c /= g;

	if (n == 0) return 0;
	long double y = (a * sqrtr + b) / c; i64 floory = y;
	
	if (floory >= 1) return n * (n + 1) / 2 * floory + calc(a, b - floory * c, c, n);
	
	i64 nn = y * n;
	tie(a, b, c) = inverse(a, b, c);
	return n * nn - calc(a, b, c, nn);
}

void solve() {
	cin >> n >> r; sqrtr = sqrtl(r);
	if ((i64)sqrtr * (i64)sqrtr == r) cout << ((i64)sqrtr & 1 ? (n & 1 ? -1 : 0) : n) << "\n";
	else cout << n + 4 * calc(1, 0, 2, n) - 2 * calc(1, 0, 1, n) << "\n";
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
   cout << "Check array size pls sir" << endl;
#endif

}









































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 1ms
memory: 3644kb

input:

10
37708 7
69538 9
38134 80
3473 16
92954 13
29430 44
17426 96
15663 11
75821 83
47428 54

output:

-2
0
2
3473
-2
0
-4
-5
-5
2

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 3592kb

input:

10
59376 73
9360 29
30305 23
10559 2
73528 58
41269 86
40784 19
43858 53
39002 87
95066 41

output:

0
10
-3
-1
0
3
2
4
-16
18

result:

ok 10 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 3728kb

input:

10
60076 48
38847 70
59252 1
74762 70
7812 19
90811 58
11634 94
96907 88
20652 84
16802 17

output:

4
3
0
2
-10
-3
2
5
0
12

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 1ms
memory: 3660kb

input:

100
5540012 1
7902151 435
2104636 10
9874979 944
9491828 422
1658084 527
7456856 362
5162458 955
9651886 169
5078624 193
8057854 280
1938272 94
5067001 550
4903551 893
893512 764
2162009 623
332836 482
4740700 404
3261229 117
576808 403
3649120 902
8373985 714
4615642 63
4768081 913
9387232 200
7555...

output:

0
-29
-2
-1
0
-4
-2
-4
0
8
6
-2
9
3
-4
-17
-18
20
5
-18
22
3
-18
-19
8
-6
-5
34
2
-3
-1
-4
4
0
12
10
4
-9
1
-44
1
4
-7
-1
-1
-1
3
-53
-18
13
-7
4
2
0
32
-2
-6
-2
10
0
0
3
-23
-1
-3
0
-8
-12
-45
0
-4
-5
15
4
-12
5
-18
3693162
-30
-6
-20
-21
4632970
1
2
-2
9
-54
1
-3
1
4
12
-28
-5
-8
16
17
6
-9

result:

ok 100 lines

Test #5:

score: 10
Accepted
time: 1ms
memory: 3672kb

input:

100
4630212 87
9248078 426
6891066 219
4247609 960
1866556 929
9255581 91
3083606 560
2453102 63
6439983 356
2689201 554
7120847 38
7118187 525
18218 701
6992930 97
26476 15
3704161 725
6145345 847
8807336 286
3922305 463
18109 881
5995126 694
9032662 375
7221174 552
5554424 767
4939652 64
2379949 1...

output:

-20
-4
-18
1
-8
3
-2
-14
3
3
13
3
42
-10
-14
3
-9
4
-3
-3
2
-22
0
-52
4939652
17
10
0
3
4117917
15
6
-30
-38
0
27
-5
6
-1
-3
-5
12
-7
28
0
4
-29
4
-3
-46
14
0
-1
13
-13
-28
23
-2
-17
-3
0
10
-9
8
5
-6
5436599
-67
-28
-5
30
-2
1
-3
2
0
-3
-98
-49
7
9
4
11
7
-1
3
13
-31
6
0
-33
-5
8
16
-16
-2
-6
-23
5...

result:

ok 100 lines

Test #6:

score: 10
Accepted
time: 1ms
memory: 3724kb

input:

100
568277 485
1449753 186
2430838 69
6097682 1000
4979129 54
6573210 139
9897598 981
4458804 115
8493265 267
5503960 958
7754834 581
6738607 452
370002 483
2640861 505
3616507 143
8969813 79
2747402 602
5366043 787
8679164 727
6657432 521
189605 861
1660254 865
9967933 931
1481056 74
8602856 448
78...

output:

61
-1
6
8
13
-2
6
-2
-3
-10
-6
1
-36
5
-39
-9
4
1
-50
4
7
4
-1
0
0
0
-1
7
2
-16
-19
-3
-25
-21
4
-14
8
1
9
-3
-19
-14
-2
7
-15
-4
-8
5
-4
-2
2
3
-3
0
10
-5
13
22
27
-30
-1
0
7
-1
-12
-1
6
-3
3
-1
3
-5
-22
1
0
-14
-11
4
-2
5
7
3
3
-1
0
26
-5
9
-2
21
25
10
-5
2
-26
26
6
18
4
7

result:

ok 100 lines

Test #7:

score: 10
Accepted
time: 20ms
memory: 3596kb

input:

10000
631007895 60
383922033 63
280016433 29
347027013 58
428062961 85
819829956 78
275768954 25
778215153 94
740955184 73
77014552 44
224648232 20
388215231 86
375284766 58
198095921 73
336210501 25
333543741 89
449063074 80
289962625 90
556278511 72
637661903 7
952148968 29
447686921 10
251154897 ...

output:

-9
-27
9
-1
23
8
0
-1
6
0
8
13
4
3
-1
21
2
1
7
-1
24
-3
11
16
5
-10
-26
11
-11
-3
-6
-1
-15
-4
-49
38
5
18
6
-1
-2
-1
2
-6
816132226
14
-6
-4
5
-7
-2
-5
-45
27
-14
-7
-6
10
17
39402409
-4
22
-24
816412577
-3
1
2
1
13
4
9
-7
813848979
-2
7
4
288769046
-12
17
-1
-6
8
-1
0
11
-6
-3
254614147
2
3
2
3141...

result:

ok 10000 lines

Test #8:

score: 10
Accepted
time: 25ms
memory: 3528kb

input:

10000
503319017 335
413716092 897
661093208 958
661306042 634
124257053 680
513264774 946
522922726 782
748686430 782
670208115 681
353040453 833
20125598 380
176913280 343
869661296 824
664105797 498
186457774 77
127964044 727
40653113 554
528554968 387
495945817 308
303462004 664
353009120 131
832...

output:

-39
-26
-34
-4
33
10
-38
-46
-11
7
2
-24
2
31
4
-30
1
-8
-7
-2
-10
-1
0
39
-11
-42
-1
3
-17
-19
5
0
-3
5
-3
-6
4
11
-1
38
5
-6
-5
3
12
-6
30
1
-10
3
3
77
-47
1
-46
0
-1
-15
5
1
-23
-89
-16
-12
-4
4
-2
17
0
5
-13
4
3
-40
-2
-2
-3
6
-35
-1
-13
4
8
-40
1
13
-4
1
11
21
-46
-9
7
15
-5
-1
-28
-85
-5
-4
-3...

result:

ok 10000 lines

Test #9:

score: 10
Accepted
time: 31ms
memory: 3596kb

input:

10000
478973133 8220
646685093 6929
319219559 7366
310897610 3205
801884864 4934
961964821 5580
843127736 8427
705144026 1221
621403018 3726
27088125 9386
54900007 4707
769719411 8840
265661605 2561
117532764 166
237176664 6938
800894259 8674
871899887 3096
58053871 8536
590953398 1380
982566506 606...

output:

-53
-5
-3
6
22
7
-178
2
4
27
-3
61
5
4
0
-11
-3
-1
0
-6
-11
-65
13
-21
0
0
-8
11
-5
47
5
2
9
742169774
-1
0
2
-2
-15
-10
7
15
1
131
-4
24
-1
0
88
-12
18
-4
-180
-31
10
9
-10
-96
4
2
-28
4
-5
0
-13
0
-42
-46
-18
-5
-11
-4
5
80
1
-34
-12
-3
3
-10
20
8
-8
22
-27
19
-21
-13
-1
-1
-97
-35
-7
-25
-19
4
6
...

result:

ok 10000 lines

Test #10:

score: 10
Accepted
time: 20ms
memory: 3624kb

input:

10000
424217816 96
605089831 52
732654064 30
669647487 57
595568934 7
62523527 46
938890183 63
837791474 95
383966699 6
686681698 73
42834085 23
375710745 69
912358250 96
804815989 22
254041255 11
879623314 88
730358325 3
690503483 16
766302978 55
548354317 1
560081953 5
497037581 50
569516360 14
64...

output:

-12
3
-2
-3
-2
-1
-29
-6
11
-10
-1
1
-6
11
-9
-2
-5
690503483
-2
-1
15
1
-4
2
1
-6
9
-19
-3
7
6
-14
-4
2
3
20
-8
-1
7
-7
667243127
13
2
2
10
0
3
-1
5
-7
-7
979146442
-22
-18
-8
0
10
1
1
2
-8
0
11
224413155
1
25
7
-2
23
-10
-1
-9
5
6
-2
6
8
-4
0
-25
10
-12
-5
10
5
11
1
7
10
10
6
-10
-22
-2
8
9
-12
-1...

result:

ok 10000 lines