前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >BZOJ3288: Mato矩阵(欧拉函数 高斯消元)

BZOJ3288: Mato矩阵(欧拉函数 高斯消元)

作者头像
attack
发布2018-07-27 15:24:45
2100
发布2018-07-27 15:24:45
举报

Time Limit: 10 Sec  Memory Limit: 128 MB

Submit: 386  Solved: 296

[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想知道这个矩阵的行列式的值,你能求出来吗?

Input

一个正整数n mod1000000007

n<=1000000

Output

n行n列的Mato矩阵的行列式。

Sample Input

5

Sample Output

16

HINT

Source

By taorunz

Orz PoPoQQQ

高斯消元之后发现对角线是欧拉函数。。

然后就做完了。

代码语言:javascript
复制
// luogu-judger-enable-o2
#include<cstdio>
#include<algorithm>
#define LL long long 
using namespace std;
const int MAXN = 1e7 + 10, mod = 1e9 + 7;
int N;
LL ans = 1;
int prime[MAXN], tot, vis[MAXN], phi[MAXN];
void GetPhi(int N) {
    phi[1] = 1;
    for(int i = 2; i <= N; i++) {
        if(!vis[i]) prime[++tot] = i, phi[i] = i - 1;
        for(int j = 1; j <= tot && i * prime[j] <= N; j++) {
            vis[i * prime[j]] = 1;
            if(i % prime[j] == 0) phi[i * prime[j]] = phi[i] * prime[j];
            else phi[i * prime[j]] = phi[i] * phi[prime[j]];
        }
    }
}
int main() {
    scanf("%d", &N);
    GetPhi(1e6 + 10);
    for(int i = 1; i <= N; i++) ans = (1ll * ans * phi[i]) % mod;
    printf("%lld", ans);
    return 0;
}
/*
123 321
*/
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-07-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Description
  • Input
  • Output
  • Sample Input
  • Sample Output
  • HINT
  • Source
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档