Luogu5221 Product

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

\(n\leq10^6\)

小清新数学题、、、


化式子

\[\begin{aligned}&\displaystyle\prod_{i=1}^n\prod_{j=1}^n{\frac{\operatorname{lcm}(i,\ j)}{\gcd(i,\ j)}}\\&=(\displaystyle\prod_{i=1}^n\prod_{j=1}^nij)(\displaystyle\prod_{i=1}^n\prod_{j=1}^n\gcd(i,\ j))^{-2}\\&=(\displaystyle\prod_{i=1}^ni^nn!)(\displaystyle\prod_{d=1}^n\prod_{i=1}^n\prod_{j=1}^nd[\gcd(i,\ j)=d])^{-2}\\&=n!^{2n}(\displaystyle\prod_{d=1}^nd^{\displaystyle\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{n}{d}\rfloor}[\gcd(i,\ j)=1]})^{-2}\\&=n!^{2n}(\displaystyle\prod_{d=1}^nd^{2\times(\displaystyle\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\varphi(i))-1})^{-2}\end{aligned}
\]

但是这道题卡时间卡空间、、、

而 \(\varphi\) 前缀和会爆 \(int\) ,所以用欧拉定理,卡卡空间卡卡常就吼辣

时间复杂度 \(O(n\log n)\)

代码

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e6 + 10, P = 104857601;
int n, tot, p[maxn / 10], phi[maxn];
bitset <maxn> f; inline int mod(int x, int P) {
return x < P ? x : x - P;
} inline int qp(int a, int k) {
int res = 1;
for (; k; k >>= 1, a = 1ll * a * a % P) {
if (k & 1) res = 1ll * res * a % P;
}
return res;
} inline void sieve() {
phi[1] = 1;
for (int i = 2; i <= n; i++) {
if (!f[i]) p[++tot] = i, phi[i] = i - 1;
for (int j = 1; j <= tot && i * p[j] <= n; j++) {
f[i * p[j]] = 1;
if (i % p[j] == 0) {
phi[i * p[j]] = phi[i] * p[j]; break;
}
phi[i * p[j]] = phi[i] * phi[p[j]];
}
}
for (int i = 1; i <= n; i++) {
phi[i] = mod(mod(phi[i] << 1, P - 1) + phi[i - 1], P - 1);
}
} int main() {
scanf("%d", &n);
sieve();
int s = 1;
for (int i = 1; i <= n; i++) {
s = 1ll * s * i % P;
}
int ans = qp(s, n << 1), sum = 1;
for (int i = 1; i <= n; i++) {
sum = 1ll * sum * qp(i, mod(phi[n / i] + P - 2, P - 1)) % P;
}
sum = qp(sum, P - 2);
sum = 1ll * sum * sum % P;
printf("%d", 1ll * ans * sum % P);
return 0;
}

Luogu5221 Product的更多相关文章

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

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  2. [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 ...

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

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

  4. vector - vector product

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

  5. 1 Maximum Product Subarray_Leetcode

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

  6. Leetcode Maximum Product Subarray

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

  7. Where product development should start

    We all need to know our customers in order to create products they’ll actually buy. This is why the  ...

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

    Given an integers array A. Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B WI ...

  9. sp_addlinkedserver '(null)' is an invalid product name

    使用SSMS 2008客户端工具逆向生成了创建链接服务器的脚本时,在测试环境执行是报如下错误:'(null)' is an invalid product name. USE [master] GO ...

随机推荐

  1. VMWAR-workstatuon : 安装win10、server 2008 r2、server 2012 r2

    最新版的VMWAR 不是很文档,建议大家还是下载稳定版,截止当前最新版的为15,用了,有点问题. 换成14~ 可以了.(15创建虚拟机安装vmware tools 怎么都安装不了). 关于创建虚拟机, ...

  2. 关于购物车添加按钮的动画(vue.js)

    来自:https://segmentfault.com/a/1190000009294321 (侵删) git 源码地址  https://github.com/ustbhuangyi/vue-sel ...

  3. HTML5效果:实现树叶飘落

    实现如图所示的东西效果(落叶下落): html代码: <!DOCTYPE html> <html> <head> <title>HTML5树叶飘落动画& ...

  4. IIS下配置跨域设置Access-Control-Allow-Origin

    设置Access-Control-Allow-Origin 打开IIS,找到“HTTP响应标头”点进去, 在右侧可以看到添加,然后添加如下标头即可 Access-Control-Allow-Heade ...

  5. Spring学习之旅(三)Spring工作原理初探

    详细的废话相信很多书籍视频资料都已经很多了,这里说几个小编个人认为对于理解Spring框架很重要的点.欢迎批评指正. 1)Spring的控制反转 先说说“依赖”,在面向对象程序设计中,类A中用到了类B ...

  6. BGP 优选短的AS号路径实践总结

    BGP优选AS号短的路径作为首选路由的验证结果 1.结论: (1)EBGP会优选AS号少的路径作为转发路径,当优选路径失效时,再选择次选路由. (2)EBGP邻居建立在直连设备之间. (3)IBGP邻 ...

  7. C# 简单实现直线方程,抛物线方程

    本例子是简单的在WinForm程序中实现在坐标系中绘制直线方程,抛物线方程,点.重新学习解析几何方面的知识.仅供学习分享使用,如有不足之处,还请指正. 涉及知识点: 直线方程的表达方式:一般表达式Ax ...

  8. Physical Plausible Shading

    问所有人一个简单的问题,为什么我们做片子,CG生产的效果,就是不如论文中样图结果.难道是论文中用了某些神奇的黑科技?或者是依赖PS伪造的图?你当然不可能怀疑Cornell.Stanford这些一流机构 ...

  9. 【LeetCode】正则表达式匹配(动态规划)

    题目描述 给定一个字符串 (s) 和一个字符模式 (p).实现支持 '.' 和 '*' 的正则表达式匹配. '.' 匹配任意单个字符. '*' 匹配零个或多个前面的元素. 匹配应该覆盖整个字符串 (s ...

  10. .net工具基础

    MSIL Disassembler(ildasm.exe) -- 将C#程序或类库反汇编处理,显示C#编译器生成的CIL代码 C:\Program Files\Microsoft SDKs\Windo ...