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. Python importlib 动态加载模块

    # 创建一个 src 文件夹,里面有一个 commons.py 文件,内容如下 def add(): print("add ....") # 创建一个 app.py 文件,内容如下 ...

  2. CSS 定位与Z-index

    position: static   Z-index 固定是0 position: absolute/relative/fixed   Z-index 有效 在层叠显示上,所有static定位元素看作 ...

  3. 解决ie6中png图片格式不兼容问题

    在IE6中对图片格式png24支持度不高,如果使用的图片格式是png24,则会导致透明效果无法正常显示 解决方法: 1.可以使用png8来代替png24,即可解决问题,但是使用png8代替png24以 ...

  4. springboot 学习之路 6(定时任务)

    目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...

  5. Keras深度学习框架安装及快速入门

    1.下载安装Keras 如果你是安装的Anaconda组合套件,可以直接在Prompt上执行安装命令:pip install keras 注意:最下面为Successfully...表示安装成功! 2 ...

  6. [20181214]open file using O_DIRECT.txt

    [20181214]open file using O_DIRECT.txt --//因为一个测试需要,需要写一个测试小例子,验证使用O_DIRECT打开文件每次都是从磁盘读取.--//没想到浪费1个 ...

  7. SQL Server datetime类型转换超出范围的报错

    一个很基础的插入语句: insert into table1 select col1,convert(datetime,col2),convert(datetime,col3),col4,col5 f ...

  8. spyder 快捷键

    本文主要介绍了spyder的快捷键. 常用快捷键   快捷键 中文名称 Ctrl+R 替换文本 Ctrl+1 单行注释,单次注释,双次取消注释 Ctrl+4 块注释,单次注释,双次取消注释 F5 运行 ...

  9. node.js cluster模式启用方式

    众所周知,Node.js运行在Chrome的JavaScript运行时平台上,我们把该平台优雅地称之为V8引擎.不论是V8引擎,还是之后的Node.js,都是以单线程的方式运行的,因此,在多核心处理器 ...

  10. LeetCode算法题-Intersection of Two Linked Lists(Java实现)

    这是悦乐书的第178次更新,第180篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第37题(顺位题号是160).编写程序以找到两个单链表交叉的节点.例如: 以下两个链表: ...