QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56101#3004. It's a Mod, Mod, Mod, Mod WorldYaoBIG#AC ✓61ms3732kbC++1.3kb2022-10-16 23:21:232022-10-16 23:21:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-16 23:21:25]
  • 评测
  • 测评结果:AC
  • 用时:61ms
  • 内存:3732kb
  • [2022-10-16 23:21:23]
  • 提交

answer

#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); ++i)
#define revrep(i, a, n) for (auto i = n; i >= (a); --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()

using namespace std;

template<class A> string to_string(A v) {
	bool first = 1;
	string res = "{";
	for (const auto &x: v) {
		if (!first) res += ", ";
		first = 0;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }
template<class Head, class... Tail> void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

ll solve(ll a, ll b, ll c, ll n) {
	if (a >= c || b >= c) {
		ll res = solve(a % c, b % c, c, n);
		res += (a / c) * n * (n + 1) / 2;
		res += (b / c) * (n + 1);
		return res;
	}
	if (a == 0) return 0;
	return ((a * n + b) / c) * n - solve(c, c - b - 1, a, (a * n + b) / c - 1);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int cas; cin >> cas; while (cas--) {
		ll p, q, n; cin >> p >> q >> n;
		p %= q;
		ll ans = p * n * (n + 1) / 2 - q * solve(p, 0, q, n);
		printf("%lld\n", ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 28ms
memory: 3696kb

input:

91125
999956 999956 999956
999956 999956 999957
999956 999956 999958
999956 999956 999959
999956 999956 999960
999956 999956 999961
999956 999956 999962
999956 999956 999963
999956 999956 999964
999956 999956 999965
999956 999956 999966
999956 999956 999967
999956 999956 999968
999956 999956 999969
...

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
499956500946
499956500946
499957500902
499958500857
499959500811
499960500764
499961500716
499962500667
499963500617
499964500566
499965500514
499966500461
499967500407
499968500352
499969500296
499970500239
49...

result:

ok 91125 lines

Test #2:

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

input:

8000
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10
1 1 999991
1 1 999992
1 1 999993
1 1 999994
1 1 999995
1 1 999996
1 1 999997
1 1 999998
1 1 999999
1 1 1000000
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 2 999991
1 2 999992
1 2 999993
1 2 999994
1 2 999995
1 2 999...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
2
2
3
3
4
4
5
5
499996
499996
499997
499997
499998
499998
499999
499999
500000
500000
1
3
3
4
6
6
7
9
9
10
999991
999993
999993
999994
999996
999996
999997
999999
999999
1000000
1
3
6
6
7
9
12
12
13
15
1499988
1499988
1499989
1499991
1499994
1499994
149999...

result:

ok 8000 lines

Test #3:

score: 0
Accepted
time: 55ms
memory: 3656kb

input:

100000
848401 999985 1000000
999527 999616 1000000
999789 999914 1000000
999479 999722 1000000
999841 999933 1000000
406226 999991 1000000
940598 999982 1000000
999708 999994 1000000
948123 999993 1000000
999789 999851 1000000
999522 999893 1000000
999977 999983 1000000
999912 999924 1000000
999232 ...

output:

499992309650
499992847584
499999028720
499990037714
499999288213
499994780341
499990845156
499998993982
499997047626
499998796124
499997350691
499999498946
499993962456
499999037615
499998396930
499994213619
499996210819
499998734816
499998193499
499997294296
499997311600
499997563064
499998257020
4...

result:

ok 100000 lines

Test #4:

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

input:

100000
276544 661397 84822
450280 333101 69413
273309 622139 246693
731970 90981 550001
606352 518276 101164
812691 168203 790853
98599 798097 886901
292688 792934 987579
447910 689959 311317
41624 797440 706737
921438 988902 506461
949886 363820 536239
214632 593976 642315
657797 687112 1001
481835...

output:

28050739501
11561046740
76748732242
25017313230
26215260156
66512110595
353916345605
391541916956
107399223391
281787020632
250419547980
97547118940
190750940808
345563873
290206495717
91866855387
107030416770
31409284551
81134882478
50587710613
28824979443
12077656210
126886307743
216791739528
1864...

result:

ok 100000 lines

Test #5:

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

input:

100000
803592 687221 934373
999545 991069 529082
875185 968212 727643
950635 957530 602207
885034 922979 801761
880161 961085 898509
696622 832975 941815
733134 969545 885444
971899 876472 950412
830028 716275 976560
899356 883946 787926
864158 917358 972542
863455 963893 941024
977884 822913 821837...

output:

321059666273
262172980269
352256802002
288321229980
370007657538
431772636765
392254148690
429236971285
416502688210
349742010515
348243992180
446068974702
453523417767
338149672589
355430775685
401615793680
270086747209
360313589303
370869897573
288206709315
470549116905
252046988544
427852655100
3...

result:

ok 100000 lines

Test #6:

score: 0
Accepted
time: 25ms
memory: 3732kb

input:

91125
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10
1 1 11
1 1 12
1 1 13
1 1 14
1 1 15
1 1 16
1 1 17
1 1 18
1 1 19
1 1 20
1 1 21
1 1 22
1 1 23
1 1 24
1 1 25
1 1 26
1 1 27
1 1 28
1 1 29
1 1 30
1 1 31
1 1 32
1 1 33
1 1 34
1 1 35
1 1 36
1 1 37
1 1 38
1 1 39
1 1 40
1 1 41
1 1 42
1 1 43
1 ...

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
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
1
3
3
4
6
6
7
9
9
10
12
12
13
15
15
16
18
18
19
21
21
22
24
24
25
27
27
28
30
30
31
33
33
34
...

result:

ok 91125 lines