题目

注意一下空间限制。

令\(f(n)=\prod\limits_{i=1}^n\prod\limits_{j=1}^nij,g(n)=\prod\limits_{i=1}^n\prod\limits_{j=1}^n(i,j)\)

那么答案就是\(f(n)g(n)^{-2}\).

显然\(f(n)=(n!)^{2n}\)。

而\(g(n)=\prod\limits_{d=1}^nd^{\sum\limits_{i=1}^{\lfloor\frac nd\rfloor}\sum\limits_{j=1}^{\lfloor\frac nd\rfloor}[(i,j)=1]}=\prod\limits_{d=1}^nd^{\sum\limits_{i=1}^{\lfloor\frac nd\rfloor}2\varphi(i)-1}\)。

然后就可以直接做了。

注意一下由于Euler定理指数部分的要对\(P-1\)取模。

#include<bits/stdc++.h>
using namespace std;
const int N=1000007,P=104857601,M=104857600;
int pr[N>>3],m,phi[N];bool f[N];
int inc(int a,int b){return a+=b,a>=M? a-M:a;}
int dec(int a,int b){return a-=b,a<0? a+M:a;}
int mul(int a,int b){return 1ll*a*b%P;}
int sqr(int a){return mul(a,a);}
int power(int a,int k){int r=1;for(;k;k>>=1,a=mul(a,a))if(k&1)r=mul(a,r);return r;}
int fac(int n){int s=1;for(;n;--n)s=mul(s,n);return s;}
int inv(int a){return power(a,P-2);}
int cal1(int n){return power(fac(n),n<<1);}
int cal2(int n)
{
phi[1]=f[1]=1;int ans=1;
for(int i=2,j,x;i<=n;++i)
{
if(!f[i]) pr[++m]=i,phi[i]=i-1;
for(j=1;j<=m&&i*pr[j]<=n;++j)
{
f[x=i*pr[j]]=1;
if(i%pr[j]) phi[x]=phi[i]*phi[pr[j]];
else {phi[x]=phi[i]*pr[j];break;}
}
}
for(int i=2;i<=n;++i) phi[i]=inc(phi[i-1],phi[i]);
for(int i=1;i<=n;++i) phi[i]=dec(inc(phi[i],phi[i]),1);
for(int i=1;i<=n;++i) ans=mul(ans,power(i,phi[n/i]));
return ans;
}
int main(){int n;cin>>n,cout<<mul(cal1(n),sqr(inv(cal2(n))));}

Luogu P5221 Product的更多相关文章

  1. P5221 Product(莫比乌斯反演)

    CYJian的新春虐题赛- 比赛详情 [题目链接] https://www.luogu.org/problemnew/show/P5221 求 \(\prod_{i=1}^{N}\prod_{j=1} ...

  2. 洛谷 P5221 Product 题解

    原题链接 庆祝!第二道数论紫题. 推式子真是太有趣了! \[\prod_{i=1}^n \prod_{j=1}^n \frac{\operatorname{lcm}(i,j)}{\gcd(i,j)} ...

  3. X000011

    P1890 gcd区间 \(\gcd\) 是满足结合律的,所以考虑用 ST 表解决 时间复杂度 \(O((n\log n+m)\log a_i)\) 考虑到 \(n\) 很小,你也可以直接算出所有的区 ...

  4. 【题解】Luogu P2889 [USACO07NOV]挤奶的时间Milking Time

    Luogu P2889 [USACO07NOV]挤奶的时间Milking Time 题目描述 传送门Bessie is such a hard-working cow. In fact, she is ...

  5. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  6. [LeetCode] Product of Array Except Self 除本身之外的数组之积

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  7. [LeetCode] Maximum Product Subarray 求最大子数组乘积

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  8. vector - vector product

    the inner product Givens two vectors \(x,y\in \mathbb{R}^n\), the quantity \(x^\top y\), sometimes c ...

  9. 1 Maximum Product Subarray_Leetcode

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

随机推荐

  1. AcWing:144. 最长异或值路径(dfs + 01字典树)

    给定一个树,树上的边都具有权值. 树中一条路径的异或长度被定义为路径上所有边的权值的异或和: ⊕ 为异或符号. 给定上述的具有n个节点的树,你能找到异或长度最大的路径吗? 输入格式 第一行包含整数n, ...

  2. Work Queues(工作队列)

    1.模型 2.创建生产者 package com.dwz.rabbitmq.work; import java.io.IOException; import java.util.concurrent. ...

  3. 识别C++编译器编译标准

    cout << __cplusplus<<endl; C++03:__cplusplus = 199711L C++11:__cplusplus = 201103L

  4. js小数点相乘或相除出现多位数的问题

    最近做一个支付的项目需要做个计算器,所以发现了一个问题. 比如: 0.03/0.00003=999.9999999999999 0.0003*0.3=0.000029999999999999997 0 ...

  5. VLC和Qt结合编写流媒体rtsp播放器

            VLC播放器是一款功能强大且小巧的播放器,它支持多种多样的音视频格式,比如MPEG1,2以及mp3等等.并且通过Qt和VLC的结合能让每个开发者写出自己的视频流媒体播放器.     Q ...

  6. koa 基础(十八)es6中的类、静态方法、继承

    1.app.js /** * es6中的类.静态方法.继承 */ // 定义Person类 class Person { constructor(name, age) { /*类的构造函数,实例化的时 ...

  7. FScapture录屏后导致麦克风无声问题

  8. layui 表单遇到的小问题

    select中的option 居中显示 /*select显示的option居中*/ /*.layui-select-title input{ text-align: center; }*/ /*opt ...

  9. 代码实现集合嵌套之ArrayList嵌套ArrayList

    package com.loaderman.list; import java.util.ArrayList; import com.loaderman.bean.Person; public cla ...

  10. ServiceStatusUtils判断服务是否运行

    import android.app.ActivityManager; import android.app.Service; import android.content.Context; impo ...