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.
46 lines
1.1 KiB
46 lines
1.1 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
long long fac[500];
|
|
int cnt;
|
|
void fen(int n) {
|
|
for (int i = 2; i * i <= n; i++) {
|
|
if (n % i == 0) {
|
|
fac[cnt++] = i;
|
|
while (n % i == 0) n /= i;
|
|
}
|
|
}
|
|
if (n > 1) fac[cnt++] = n;
|
|
} //素因子分解
|
|
long long ans;
|
|
int n;
|
|
const int mod = 1000000007;
|
|
void dfs(int w, int id, long long sum) {
|
|
for (int i = w; i < cnt; i++) {
|
|
long long ss = sum * fac[i];
|
|
if (id & 1) {
|
|
int tmp = n / ss;
|
|
ans += ss * (1 + tmp) * tmp / 2;
|
|
ans %= mod;
|
|
} else {
|
|
int tmp = n / ss;
|
|
ans -= ss * (1 + tmp) * tmp / 2;
|
|
ans = (ans + mod) % mod;
|
|
}
|
|
dfs(i + 1, id + 1, ss);
|
|
}
|
|
} //递归实现容斥原理
|
|
int main() {
|
|
while (scanf("%d", &n) != EOF) {
|
|
if (n == 0) break;
|
|
if (n == 1) {
|
|
cout << 0 << endl;
|
|
continue;
|
|
}
|
|
cnt = 0;
|
|
fen(n);
|
|
ans = 0;
|
|
dfs(0, 1, 1);
|
|
cout << (ans % mod - n + mod) % mod << endl;
|
|
}
|
|
return 0;
|
|
} |