CYJian的新春虐题赛- 比赛详情

[题目链接] https://www.luogu.org/problemnew/show/P5221

求 \(\prod_{i=1}^{N}\prod_{j=1}^{N}\frac{lcm(i,j)}{gcd(i,j)}\)

[题解] https://tbr-blog.blog.luogu.org/solution-p5221

对于分子:

\[\begin{aligned}
&\ \ \ \ \ \ \prod_{i=1}^{N}\prod_{j=1}^{N}i*j \\
&=(n!)^{2n}\\
\end{aligned}
\]

对于分母:

\[\begin{aligned}
&\ \ \ \ \ \ \prod_{i=1}^{N}\prod_{j=1}^{N}gcd(i,j) \\
&=\prod_{d=1}^{n}\prod_{i=1}^{n}\prod_{j=1}^{n} [gcd(i,j)==d]\\
&=\prod_{d=1}^{n}d^{\sum_{i=1}^{n}\sum_{j=1}^{n}[gcd(i,j)==d]}\\
&=\prod_{d=1}^{n}d^{\sum_{i=1}^{\frac{n}{d}}\sum_{j=1}^{\frac{n}{d}}[gcd(i,j)==1]}\\
\end{aligned}
\]

其中指数

\[\sum_{i=1}^{\frac{n}{d}}\sum_{j=1}^{\frac{n}{d}}[gcd(i,j)==1]
\]

就是仪仗队这道题

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define ll long long
#define mod 104857601
il int read()
{
re int x=0,f=1;re char c=getchar();
while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
return x*f;
}
#define maxn 1000000+5
int n,cnt,ans1=1,prim[80000],ans2=1,pai[maxn];
bool vis[maxn];
il int qpow(int a,ll b)
{
int r=1;
while(b)
{
if(b&1ll) r=1ll*r*a%mod;
b>>=1ll;
a=1ll*a*a%mod;
}
return r;
}
int main()
{
n=read();
pai[1]=1;
for(re int i=2;i<=n;++i)
{
ans1=1ll*ans1*i%mod;
if(!vis[i]) prim[++cnt]=i,pai[i]=i-1;
for(re int j=1;j<=cnt;++j)
{
if(prim[j]*i>n) break;
vis[prim[j]*i]=1;
if(i%prim[j]==0) {pai[i*prim[j]]=pai[i]*prim[j];break;}
pai[i*prim[j]]=pai[prim[j]]*pai[i];
}
}
for(re int i=1;i<=n;++i) pai[i]=pai[i]*2+pai[i-1]%(mod-1);
ans1=qpow(ans1,2*n);
for(re int i=2;i<=n;++i) ans2=1ll*ans2*qpow(i,pai[n/i]-1)%mod;
printf("%d",(1ll*ans1*qpow(1ll*ans2*ans2%mod,mod-2))%mod);
return 0;
}

P5221 Product(莫比乌斯反演)的更多相关文章

  1. Hackerrank GCD Product(莫比乌斯反演)

    题意 题目链接 Sol 一道咕咕咕了好长时间的题 题解可以看这里 #include<bits/stdc++.h> #define LL long long using namespace ...

  2. hdu1695 GCD(莫比乌斯反演)

    题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...

  3. BZOJ 2154: Crash的数字表格 [莫比乌斯反演]

    2154: Crash的数字表格 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 2924  Solved: 1091[Submit][Status][ ...

  4. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  5. Bzoj2154 Crash的数字表格 乘法逆元+莫比乌斯反演(TLE)

    题意:求sigma{lcm(i,j)},1<=i<=n,1<=j<=m 不妨令n<=m 首先把lcm(i,j)转成i*j/gcd(i,j) 正解不会...总之最后化出来的 ...

  6. 莫比乌斯函数筛法 & 莫比乌斯反演

    模板: int p[MAXN],pcnt=0,mu[MAXN]; bool notp[MAXN]; void shai(int n){ mu[1]=1; for(int i=2;i<=n;++i ...

  7. 【BZOJ-2440】完全平方数 容斥原理 + 线性筛莫比乌斯反演函数 + 二分判定

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2371  Solved: 1143[Submit][Sta ...

  8. POI2007_zap 莫比乌斯反演

    题意:http://hzwer.com/4205.html 同hdu1695 #include <iostream> #include <cstring> #include & ...

  9. hdu.5212.Code(莫比乌斯反演 && 埃氏筛)

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  10. CSU 1325 莫比乌斯反演

    题目大意: 一.有多少个有序数对(x,y)满足1<=x<=A,1<=y<=B,并且gcd(x,y)为p的一个约数: 二.有多少个有序数对(x,y)满足1<=x<=A ...

随机推荐

  1. 【259】ucpole.dat update

    2017年2月21日 57871 +0.020896 0.007232 +0.414732 0.009212 +0.418044 0.007533 p 57872 +0.022055 0.007284 ...

  2. Enumeration与Iterator的对比

    Enumeration与Iterator的对比 Enumeration 接口 Iterator 接口 参数的含义 枚举类型 迭代器元素类型 所在包 java.util 父类 无 子类 StringTo ...

  3. BitmapCutter.Core 引用步骤

    1 将BitmapCutter.Core项目或者dll引用到需要的项目底下. 2 前台页面 <img id="imgPreview1" title="点击上传图片& ...

  4. curl的特殊使用

    1.php可以通过shell_exec()和其他系统函数使用curl,也可用PHP带的libcurl库. $curl = curl_init("wwww.baidu.com"); ...

  5. 使用HttpClient进行Get通信

    --------------siwuxie095                             首先到 Apache官网 下载相关的库文件     Apache官网:http://www.a ...

  6. ngx-bootstrap使用04 carousel组件

    1 carousel 是一个通过循环播放图片.文本的幻灯片:就像一个旋转旋转木马一样,但是不支持嵌套使用 2 如何使用 2.1 搭建ngx-bootstrap使用环境 参见博文:点击前往 2.2 在模 ...

  7. Executor线程池

    Executor线程池框架: 使用线程池的优点: 1.重用存在的线程 2.减少对象创建.消亡的开销 3.性能佳 4.可有效控制最大并发线程数,提高系统资源的使用率 5.避免过多资源竞争,避免堵塞 6. ...

  8. Boost 线程学习笔记

    Bolg转载自:http://www.cnblogs.com/lvdongjie/p/4447193.html 一: 创建线程 #include <iostream> #include & ...

  9. 100200F Think Positive

    传送门 题目大意 给你一个数n和长度为n的序列,序列中的每个数均为1或-1,如果一个点j对于任意的k都满足题目中给的式子,则j是一个合法位置,问这样的j有多少个 分析 这道题有两种方法,分别对应代码1 ...

  10. Hadoop的Writerable在Spark无法序列化的问题

    Spark序列化这块网上讲的比较少,自己还没来得及看这块代码,今天编程的时候遇到一个Hadoop的Writerable实现在Spark无法序列化的问题.我的代码如下: object EntryApp ...