Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P2303 [SDOI2012] Longge 的问题

P2303 [SDOI2012] Longge 的问题

直接上莫反即可。

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <cstdio>
using namespace std;
template <class Type>
void read(Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0';
flag && (x = ~x + 1);
}
template <class Type>
void write(Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar(x % 10 + '0');
}
typedef long long LL;
LL n;
LL phi (LL x)
{
LL res = x;
for (LL i = 2; i * i <= x; i++)
if (x % i == 0)
{
res = res / i * (i - 1);
while (x % i == 0)
x /= i;
}
x > 1 && (res /= x, res *= (x - 1));
return res;
}
int main ()
{
read(n);
LL res = 0;
for (LL i = 1; i * i <= n; i++)
if (n % i == 0)
{
res += i * phi(n / i);
i * i ^ n && (res += n / i * phi(i));
}
write(res);
return 0;
}