题目链接:
3288: Mato矩阵
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
题意:
思路:
进行行列变换后得到对角行列式,结果就是对角行列式的对角线上的积,变换后是欧拉函数值;
AC代码:
/**************************************************************
Problem: 3288
User: LittlePointer
Language: C++
Result: Accepted
Time:572 ms
Memory:5196 kb
****************************************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map>
using namespace std;
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('
');
}
const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+20;
const int maxn=1e6+4;
const double eps=1e-12;
int phi[maxn];
inline LL solve(int le)
{
LL sum=1;
for(int i=2;i<=le;i++)
{
if(!phi[i])
{
for(int j=i;j<=le;j+=i)
{
if(!phi[j])phi[j]=j;
phi[j]=phi[j]/i*(i-1);
}
}
sum=sum*phi[i]%mod;
}
return sum;
}
int main()
{
int n;
read(n);
cout<<solve(n)<<"
";
return 0;
}