3288: Mato矩阵
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 303 Solved: 230
[Submit][Status][Discuss]
Description
Mato同学最近正在研究一种矩阵,这种矩阵有n行n列第i行第j列的数为gcd(i,j)。
例如n=5时,矩阵如下:
1 1 1 1 1
1 2 1 2 1
1 1 3 1 1
1 2 1 4 1
1 1 1 1 5
Mato想知道这个矩阵的行列式的值,你能求出来吗?
例如n=5时,矩阵如下:
1 1 1 1 1
1 2 1 2 1
1 1 3 1 1
1 2 1 4 1
1 1 1 1 5
Mato想知道这个矩阵的行列式的值,你能求出来吗?
Input
一个正整数n mod1000000007
Output
n行n列的Mato矩阵的行列式。
Sample Input
5
Sample Output
16
HINT
对于100%的数据,n<=1000000。
Source
分析:
YouSiki告诉我你去打个表...然后我就去打了个表...然后我只发现了对角线上的元素不是1就是偶数,然后我并没有想到其他...YouSiki告诉我这是欧拉函数啊...
What???...好吧...那就是欧拉函数吧...
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;
const int maxn=1000000+5,mod=1e9+7;
int n,ans,cnt,phi[maxn],pri[maxn],vis[maxn];
inline void prework(void){
phi[1]=1;
for(int i=2;i<=n;i++){
if(!vis[i])
pri[++cnt]=i,phi[i]=i-1;
for(int j=1;j<=cnt&&pri[j]*i<=n;j++){
vis[pri[j]*i]=1;
if(i%pri[j]==0){
phi[i*pri[j]]=phi[i]*pri[j];
break;
}
phi[i*pri[j]]=phi[i]*(pri[j]-1);
}
}
}
signed main(void){
scanf("%d",&n);
prework();ans=1;
for(int i=1;i<=n;i++)
ans=(1LL*ans*phi[i])%mod;
printf("%d
",ans);
return 0;
}
By NeighThorn