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.
37 lines
764 B
37 lines
764 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define int long long
|
|
#define endl "\n"
|
|
const int MOD = 1e9 + 7;
|
|
/*
|
|
3
|
|
4
|
|
0
|
|
|
|
答案
|
|
0
|
|
2
|
|
*/
|
|
// 求单个数值的欧拉函数值
|
|
int phi(int x) {
|
|
int res = x;
|
|
for (int i = 2; i <= x / i; i++) {
|
|
if (x % i == 0) {
|
|
res = res / i * (i - 1);
|
|
while (x % i == 0) x /= i;
|
|
}
|
|
}
|
|
if (x > 1) res = res / x * (x - 1);
|
|
return res;
|
|
}
|
|
|
|
signed main() {
|
|
int n;
|
|
while (cin >> n && n) {
|
|
// 小于n的数字中有多少个数字与n互质
|
|
int ans = n * (n - 1) / 2; // 高斯公式,(首页+末项)*项数/2
|
|
ans = (ans - phi(n) * n / 2) % MOD; // 扣除掉 phi(n)*n/2
|
|
cout << ans << endl;
|
|
}
|
|
}
|