Luogu P5221 Product
题目
注意一下空间限制。
令\(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的更多相关文章
- P5221 Product(莫比乌斯反演)
CYJian的新春虐题赛- 比赛详情 [题目链接] https://www.luogu.org/problemnew/show/P5221 求 \(\prod_{i=1}^{N}\prod_{j=1} ...
- 洛谷 P5221 Product 题解
原题链接 庆祝!第二道数论紫题. 推式子真是太有趣了! \[\prod_{i=1}^n \prod_{j=1}^n \frac{\operatorname{lcm}(i,j)}{\gcd(i,j)} ...
- X000011
P1890 gcd区间 \(\gcd\) 是满足结合律的,所以考虑用 ST 表解决 时间复杂度 \(O((n\log n+m)\log a_i)\) 考虑到 \(n\) 很小,你也可以直接算出所有的区 ...
- 【题解】Luogu P2889 [USACO07NOV]挤奶的时间Milking Time
Luogu P2889 [USACO07NOV]挤奶的时间Milking Time 题目描述 传送门Bessie is such a hard-working cow. In fact, she is ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [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 ...
- [LeetCode] Maximum Product Subarray 求最大子数组乘积
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- vector - vector product
the inner product Givens two vectors \(x,y\in \mathbb{R}^n\), the quantity \(x^\top y\), sometimes c ...
- 1 Maximum Product Subarray_Leetcode
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
随机推荐
- webpack4 单入口文件配置 多入口文件配置 以及常用的配置
单入口文件配置 webpack.config.js const path = require('path'); const HtmlWebpackPlugin = require('html-webp ...
- Java file.encoding
1. file.encoding属性的作用 file.encoding 的值是整个程序使用的编码格式. 可以使用 System.out.println(System.getProperty(&quo ...
- hotspot 线程状态
- Win10删除文件显示删除确认对话框
1.右键单击“回收站”图标:2.在弹出属性窗口中,点击“属性”选项:3.在“回收站”窗口中,在选项“显示删除确认对话框”前面打钩,并单击“确定”按钮:
- GitHub:Baidu
ylbtech-GitHub:Baidu 1.返回顶部 · duedge-recipes DuEdge百度边缘网络计算样例代码 edgeedge-computingduedge JavaScri ...
- javascript之日期对象(Date)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- php获取文件名和后缀名
php获取文件名 1 function retrieve($url) 2 { 3 preg_match('/\/([^\/]+\.[a-z]+)[^\/]*$/',$url,$match); 4 re ...
- Oracle COALESCE函数
Oracle COALESCE函数 Oracle COALESCE函数语法为COALESCE(表达式1,表达式2,...,表达式n),n>=2,此表达式的功能为返回第一个不为空的表达式,如果都为 ...
- 2.oracle数据库:[1]oracle简易客户端安装方法
准备oracle简易客户端程序,如果没有请到oracle网站下载www.oracle.com,可以下载基本包及其他扩展程序包,例如:如果要使用sqlplus则需要下载sqlplus包,笔者下载了i ...
- Jmeter实现简单web负载测试
Jmeter实现简单web负载测试 简介 Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试,但后来扩展到其他测试领域. ...