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. CSS琐碎知识点(持续补充)

    一.字体单位,pt?px?em?rem? pt:磅,一种固定长度的绝对的度量单位,是能够使用测量设备测得的长度,印刷业上经常使用,一般用于页面打印排版. px:屏幕设备上能显示出的最小的一个物理点,这 ...

  2. Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口”

    Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口” Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directo ...

  3. iOS -----------Downloading core failed:

    [!] /bin/bash -c set -e sh build.sh cocoapods-setup core is not a symlink. Deleting... Downloading d ...

  4. 多级nginx代理,获取客户端真实ip

    今天服务里的微信公众号支付业务突然不能用了,报错为网络环境未能通过安全验证,请稍后再试.检查后端日志,没有任何问题,看来是成功创建支付订单,但是调起支付时出现了问题.上网查了一下,这个报错的直接原因是 ...

  5. Linux下对lvm逻辑卷分区大小的调整(针对xfs和ext4不同文件系统)

    当我们在安装系统的时候,由于没有合理分配分区空间,在后续维护过程中,发现有些分区空间不够使用,而有的分区空间却有很多剩余空间.如果这些分区在装系统的时候使用了lvm(前提是这些分区要是lvm逻辑卷分区 ...

  6. 记一次坑爹的ORA-01152&ORA-01110错误

    最近做RMAN还原时遇到了一次非常坑爹的ORA-01152&ORA-01110错误.遇到的具体错误信息如下所示: RMAN> alter database open resetlogs; ...

  7. python3+正则表达式爬取 猫眼电影

    '''Request+正则表达式抓取猫眼电影TOP100内容''' import requests from requests.exceptions import RequestException i ...

  8. python——作用域之LEGB规则

    1 变量的作用域 Python是静态作用域,也就是说在Python中,变量的作用域源于它在代码中的位置:在不同的位置,可能有不同的命名空间.命名空间是变量作用域的体现形式. 2 LEGB各自代表的含义 ...

  9. python发展史

    一:Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum)(龟叔).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹 打发时间,决心开发一个新的脚本解释程序, ...

  10. LeetCode算法题-Number of Segments in a String(Java实现)

    这是悦乐书的第226次更新,第239篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第93题(顺位题号是434).计算字符串中的段数,其中段定义为非空格字符的连续序列.请注 ...