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 ...
随机推荐
- python测试网站访问速度
# -*- coding: utf-8 -*- # @Author : Felix Wang # @time : 2018/8/13 22:13 # pip3 install pycurl impor ...
- [题解] [AHOI2009] 跳棋
题面 题解 分类讨论, 考虑到只要所有的偶数点上都有棋子, 最左边的棋子就可以跳到最右边 题目第一问让我们求最少的在白格子上必须放的棋子数(不用考虑行动中放的棋子数) 考虑到这几种情况 有不少于两个红 ...
- rabbitmq访问控制试坑篇
访问控制我理解就是两层,第一层是Virtual host,相当于一个个独立主机 第二层是这个permissions,对照下图权限表 权限表(重要!) 需求 configgure write read ...
- (九)C语言之scanf
- LeetCode 260. 只出现一次的数字 III(Single Number III)
题目描述 给定一个整数数组 nums,其中恰好有两个元素只出现一次,其余所有元素均出现两次. 找出只出现一次的那两个元素. 示例 : 输入: [1,2,1,3,2,5] 输出: [3,5] 注意: 结 ...
- GIS面积计算问题
好长时间不更新了,今天说点干货,项目用到的. 1.项目中要用到计算面积的,根据火星坐标: 2.百度找了各种面积计算,google了半天,也没发现那个比较准确: 直接说干货吧.咱也高大上一会,用 Arc ...
- pytest.fixture和普通函数调用
普通函数嗲用def one(): a="aaaaaaaaaaa" return a def test_one(): s=one() print (s) test_one() pyt ...
- LVS负载均衡(LVS简介、三种工作模式、十种调度算法)
一.LVS简介 LVS(Linux Virtual Server)即Linux虚拟服务器,是由章文嵩博士主导的开源负载均衡项目,目前LVS已经被集成到Linux内核模块中.该项目在Linux内核中实现 ...
- Python安装远程调试Android需要的扩展脚本
http://android-scripting.googlecode.com/hg/python/ase/android.py 拷贝到/Python27/Lib/site-packages这个目录下 ...
- php安装compoer install
1.先确定php运行版本为7.1以上 2.在phpstorm中 或者在项目根目录按住shift+有单击点击“在此处打开命令窗口”运行composer install 3出现这个证明安装成功 . 会遇到 ...