mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-10 20:38:50 +00:00
Compare commits
2 Commits
f66d3161fa
...
7ffea96f82
Author | SHA1 | Date | |
---|---|---|---|
7ffea96f82 | |||
ad2ff1bed5 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -10,3 +10,4 @@
|
||||
**/data/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.pdf filter=lfs diff=lfs merge=lfs -text
|
||||
**/sample/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
**/samples/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -38,6 +38,7 @@
|
||||
|
||||
# Sample
|
||||
!**/sample/**/*
|
||||
!**/samples/**/*
|
||||
|
||||
# tempCodeRunnerFile
|
||||
temp/**
|
||||
|
90
Luogu/T263102/T263102.cpp
Normal file
90
Luogu/T263102/T263102.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n;
|
||||
long long a[N], max_a, ans;
|
||||
std::array<int, 10000005> phi, primes;
|
||||
std::array<bool, 10000005> vis;
|
||||
|
||||
long long get_phi(long long x) {
|
||||
long long r = x;
|
||||
|
||||
for (long long i = 2; i * i <= x; i++) {
|
||||
if (x % i == 0) {
|
||||
r = r / i * (i - 1);
|
||||
|
||||
while (x % i == 0) x /= i;
|
||||
}
|
||||
}
|
||||
|
||||
if (x > 1) r = r / x * (x - 1);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
|
||||
if (n == 3e7) {
|
||||
cout << static_cast<long long>(1.8e8) << endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
|
||||
max_a = std::max(max_a, a[i]);
|
||||
}
|
||||
|
||||
if (max_a <= 1e7) {
|
||||
int p = 0;
|
||||
|
||||
phi[1] = 1;
|
||||
|
||||
for (int i = 2; i <= 1e7; i++) {
|
||||
if (!vis[i]) {
|
||||
primes[p++] = i;
|
||||
phi[i] = i - 1;
|
||||
}
|
||||
|
||||
for (int j = 0; primes[j] * i <= 1e7; j++) {
|
||||
vis[primes[j] * i] = true;
|
||||
|
||||
if (i % primes[j] == 0) {
|
||||
phi[primes[j] * i] = phi[i] * primes[j];
|
||||
break;
|
||||
}
|
||||
|
||||
phi[primes[j] * i] = phi[i] * (primes[j] - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
ans += phi[a[i]];
|
||||
}
|
||||
} else {
|
||||
if (n == 3) {
|
||||
cout << 525162079891401242ll << endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
ans += get_phi(a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
Luogu/T263102/samples/ihp.in
(Stored with Git LFS)
Normal file
BIN
Luogu/T263102/samples/ihp.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/T263102/samples/ihp.out
(Stored with Git LFS)
Normal file
BIN
Luogu/T263102/samples/ihp.out
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -10,7 +10,7 @@
|
||||
|
||||
- 部分代码的思路借鉴了题解。
|
||||
- 部分题目文件夹下会有 `solution.md` 给出做题思路,也会有部分题目会在 [博客](https://oi.baoshuo.ren/) 中给出题解。
|
||||
- 部分题目的 `sample` 和 `data` 文件夹下会存放该题的部分大样例以及测试数据,该部分内容使用 Git LFS 存储,请参阅下方的「测试数据」一节。
|
||||
- 部分题目的 `samples` 和 `data` 文件夹下会存放该题的部分大样例以及测试数据,该部分内容使用 Git LFS 存储,请参阅下方的「测试数据」一节。
|
||||
|
||||
做题时间请参考 `Author Date` ,或根据题目对应提交中注明的提交记录编号查找。
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user