QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741972#9531. Weird Ceilingfeng_LrefrainRE 10ms7172kbC++142.2kb2024-11-13 15:33:272024-11-13 15:33:30

Judging History

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

  • [2024-11-13 15:33:30]
  • 评测
  • 测评结果:RE
  • 用时:10ms
  • 内存:7172kb
  • [2024-11-13 15:33:27]
  • 提交

answer

/*
 * ============================
 * @Author: feng_Lrefrain
 * @DateTime: 2024-11-13 14:41:05
 * ============================
 */
#include <bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define rep(I,S,N) for(int I=(S);I<(N);++I)
#define per(I,S,N) for(int I=(N)-1;I>=(S);--I)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef double db;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
//inline ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
//inline ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
//inline ll ksm(ll a,ll b,ll p) {ll ans=1;while(b){if(b&1)ans=(ans*a)%p;b>>=1;a=(a*a)%p;}return ans%p;}
//inline ll lowbit(int x) {return x&(-x);}
//inline int read() {
//    int x = 0;
//    char ch = getchar();
//    while (ch < '0' || ch > '9') ch = getchar();
//    while (ch <= '9' && ch >= '0') {
//        x = (x << 1) + (x << 3) + (ch ^ 48);
//        ch = getchar();
//    }
//    return x;
//}
const int N = 1e6 + 10, M = 998244353, MM = 1e9 + 7, inf = 1e18;

int cnt, primes[N];
bool st[N];
void get_primes(int n) {
	for (int i = 2; i <= n; ++ i) {
		if (!st[i]) primes[cnt ++] = i;
		for (int j = 0; primes[j] <= n / i; ++ j) {
			st[primes[j] * i] = true;
			if (primes[j] % i == 0) break; 
		}
	}
}
set<int> ans;
void func(int a) {
	ans.clear();
    for (int i = 1; i <= a / i; ++ i) {
        if (a % i == 0) {
            ans.insert(i);
            if (i != a / i) ans.insert(a / i);
        }
    }
}

void solve() {
	int n, sum = 0; cin >> n;
	if (!st[n]) cout << n * (n - 1) + 1 << '\n';
	else {
		int tmp = 1;
		func(n);
		for (const auto &i : ans) {
			if (i == 1) {
				continue;
			}
			if (i == n) break;
			if (tmp == 1) sum += (i - tmp) * n;
			else {
				sum += (i - tmp) * (n / tmp);
			}
			tmp = i;
			// cout << sum << " " << i << " " << tmp << '\n';
		}
		sum += (n - 1 - tmp + 1) * (n / tmp) + 1;
		cout << sum << '\n';
	}
}
/*


*/
signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	get_primes(N);
	int _ = 1;
	cin >> _;
	while (_ --) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 6880kb

input:

3
5
451
114514

output:

21
10251
7075858

result:

ok 3 lines

Test #2:

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

input:

1000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101...

output:

1
3
7
9
21
16
43
25
37
36
111
41
157
64
71
65
273
73
343
86
113
144
507
101
201
196
163
134
813
137
931
161
221
324
295
169
1333
400
287
205
1641
218
1807
254
277
576
2163
241
589
301
443
326
2757
298
507
317
533
900
3423
315
3661
1024
439
385
625
386
4423
494
737
437
4971
394
5257
1444
551
590
969
...

result:

ok 1000 lines

Test #3:

score: -100
Runtime Error

input:

1000
999999001
999999002
999999003
999999004
999999005
999999006
999999007
999999008
999999009
999999010
999999011
999999012
999999013
999999014
999999015
999999016
999999017
999999018
999999019
999999020
999999021
999999022
999999023
999999024
999999025
999999026
999999027
999999028
999999029
99999...

output:


result: