书信

题目大意:有 n 个小朋友,编号为 1 到 n,他们每人写了一封信,放到了一个信箱里, 接下来每个人从中抽取一封书信。显然,这样一共有 \(n!\)种拿到书信的情况。 现在亮亮规定,对任意的 1<=x,y<=n,如果 x 号小朋友拿到 u 号小朋友写的 书信,y 号小朋友拿到 v 号小朋友写的书信,那么(x+y)号小朋友必须拿到(u+v) 号小朋友写的书信(这里的加法若和超过了 n,那么就减去 n)。 小林想知道,总共有多少种拿到书信的情况呢?

我打表的时候发现了,如果这个数字是一个素数,那么ans就为素数减一,没有联想到欧拉函数,这是我的过

其实我距离正解只差那么一点点

证明不会

打表会

欧拉函数公式:\(\phi(x) = x\times \prod_{i=1}^{m}(1-\dfrac 1 {p_i})\),其中m为素因子个数

在分解质因数的时候顺便求一下就好了

代码如下:(求一个裸的欧拉函数)

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
50
51
#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;

const int N = 1e5 + 66;

inline ll read()
{
int s(0), w(1);
char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}

inline void put(ll x)
{
if (! x) putchar('0');
if (x < 0) putchar('-'), x = -x;
int num(0); char c[66];
while (x) c[++ num] = x % 10 + 48, x /= 10;
while (num) putchar(c[num --]);
return (void)(putchar('\n'));
}

int n;

inline int solve()
{
int res = n, i;
for (i = 2; i * i <= n; ++ i)
{
while (n % i == 0)
{
res = res / i * (i - 1);
while (n % i == 0) n /= i;
}
}
if (n > 1) res = res / n * (n - 1);
return res;
}

signed main()
{
n = read();
put(solve());

fclose(stdin), fclose(stdout);
return 0;
}