0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 17:58:47 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
7ffea96f82
T263102 函数(ihp)
https://www.luogu.com.cn/record/85427845
2022-08-29 14:32:54 +08:00
ad2ff1bed5
fix: samples 2022-08-29 09:28:17 +08:00
6 changed files with 99 additions and 1 deletions

1
.gitattributes vendored
View File

@ -10,3 +10,4 @@
**/data/**/* filter=lfs diff=lfs merge=lfs -text **/data/**/* filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text *.pdf filter=lfs diff=lfs merge=lfs -text
**/sample/**/* 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
View File

@ -38,6 +38,7 @@
# Sample # Sample
!**/sample/**/* !**/sample/**/*
!**/samples/**/*
# tempCodeRunnerFile # tempCodeRunnerFile
temp/** temp/**

90
Luogu/T263102/T263102.cpp Normal file
View 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

Binary file not shown.

BIN
Luogu/T263102/samples/ihp.out (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -10,7 +10,7 @@
- 部分代码的思路借鉴了题解。 - 部分代码的思路借鉴了题解。
- 部分题目文件夹下会有 `solution.md` 给出做题思路,也会有部分题目会在 [博客](https://oi.baoshuo.ren/) 中给出题解。 - 部分题目文件夹下会有 `solution.md` 给出做题思路,也会有部分题目会在 [博客](https://oi.baoshuo.ren/) 中给出题解。
- 部分题目的 `sample` 和 `data` 文件夹下会存放该题的部分大样例以及测试数据,该部分内容使用 Git LFS 存储,请参阅下方的「测试数据」一节。 - 部分题目的 `samples` 和 `data` 文件夹下会存放该题的部分大样例以及测试数据,该部分内容使用 Git LFS 存储,请参阅下方的「测试数据」一节。
做题时间请参考 `Author Date` ,或根据题目对应提交中注明的提交记录编号查找。 做题时间请参考 `Author Date` ,或根据题目对应提交中注明的提交记录编号查找。