行列式消元-》打表找规律,因为搜题的时候看到线筛,就疯狂的从线筛上找规律:
f[p]=p-1
f[p*i](i%p==0) =f[i]*p
f[p*i](i%p!=0) =f[i]*f[p]
据说这是Phi?我没看出来,也没有什么影响
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define md 1000000007
#define ll long long
#define inf (int) 1e9
#define eps 1e-8
#define N 1000010
using namespace std;
ll f[N];
int ss[N],mark[N];
int main()
{
int w=0,n;
scanf("%d",&n);
f[1]=1;
for (int i=2;i<=n;i++)
{
if (!mark[i]) { ss[++w]=i; f[i]=i-1; }
for (int j=1;j<=w&&ss[j]*i<=n;j++)
{
int p=ss[j];
mark[i*p]=1;
if (i%p==0) { f[i*p]=f[i]*p; break;}
else f[i*p]=f[i]*f[p];
}
}
ll ans=1;
//for (int i=1;i<=n;i++) printf("%d ",f[i]); printf("\n");
for (int i=1;i<=n;i++) ans=ans*f[i]%md;
printf("%lld\n",ans);
return 0;
}