题目

注意一下空间限制。

令\(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. DelayQueue实现延迟队列

    public class Q { public static void main(String[] args) throws Exception { DelayQueue<Order> o ...

  2. Linux-expect脚本-编写一个expect脚本

    1.声明expect #!/usr/bin/expect -f 2.设置超时时间,获取参数 set ip [lindex $argv 0 ] //接收第一个参数,并设置IP set password ...

  3. Nginx-rtmp直播之业务流程分析

    1. 综述 1.1 直播原理 使用 obs 向 nginx 推送一个直播流,该直播流经 nginx-rtmp 的 ngx_rtmp_live_module 模块转发给 application live ...

  4. koa 基础(十六)koa 中 session 的使用

    1.app.js /** * koa 中 session 的使用 * 1.npm install koa-session --save * 2.const session = require('koa ...

  5. H264编码原理以及I帧、B和P帧详解, H264码流结构分析

    H264码流结构分析 http://blog.csdn.net/chenchong_219/article/details/37990541 1.码流总体结构: h264的功能分为两层,视频编码层(V ...

  6. rocketmq的以集群模式MessageModel.CLUSTERING实现消费者集群消费消息,实现负载均衡

    package com.bfxy.rocketmq.model; import java.util.List; import org.apache.rocketmq.client.consumer.D ...

  7. linux系统安装zint

    背景: 今天代码拉下了发现启动时报错,一看原来是同事用了zint的gem,我又没安,然后花了点时间解决,但其中踩了几次坑,所以打算记录下: 一.zint开源库的介绍 zint 是一个开源的条码编码库, ...

  8. [SPSS]如何利用spss进行单侧检验

    根据网上经验来看,结论如下: 单双侧t检验,t值不变,p值除以2即为单侧p值.

  9. 小D课堂 - 新版本微服务springcloud+Docker教程_2_03常见的微服务框架

    笔记 3.常见的微服务框架     简介:讲解常用的微服务框架 consumer: 调用方         provider: 被调用方         一个接口一般都会充当两个角色(不是同时充当) ...

  10. azure sql database CPU troubleshooting

    描述 最新我们一个稳定运行快一年的项目突然出现CPU方面的性能问题,该项目使用的azure sql database  P2 500DTU,运维同事监控到CPU使用非常高,客户反馈系统运行也比较卡.看 ...