You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
// 60以内的质数列表
int p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
signed main() {
int n;
while (cin >> n) {
int s = 1, t; // s=1表示最起码数字1符合要求
for (int i = 0; i < 17; i++) { // 三层循环遍历质数数组p枚举第一个因子
t = pow(n, 1.0 / p[i]) - 1; // 计算出指数=p[i]的数的个数,需要减去1见下面的注释解释
if (!t) break; // 扣除完1^2后没有了那太白扯了
/*
int n = 10;
cout << (int)pow(n, 1.0 / 2) << endl;
输出3理解一下
10以内可以描述为x^2的有1^2 2^2 3^2
这样就是说上面的算法把数字1记录在内了。
*/
s += t; // t个但数字1不能考虑
for (int j = i + 1; j < 17; j++) { // 三层循环,枚举第二个因子,避让第一个因子
t = pow(n, 1.0 / (p[i] * p[j])) - 1; // 计算出指数=p[i]*p[j]的数的个数
if (!t) break; // 扣除完1^2后没有了那太白扯了
s -= t; // 两个的要减
for (int k = j + 1; k < 17; k++) { // 三层循环,枚举第三个因子,避让第一、第二个因子
t = pow(n, 1.0 / (p[i] * p[j] * p[k])) - 1; // 计算出指数=p[i]*p[j]*p[k]的数的个数
if (!t) break; // 扣除完1^2后没有了那太白扯了
s += t; // 三个的要加
}
}
}
cout << s << endl;
}
}