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. javascript对象与方法

    对象与方法 一.数组(Array) 1.使用new关键字创建数组 var box = new Array();                                     //创建了一个数 ...

  2. [工具配置]使用requirejs模块化开发多页面一个入口js的使用方式

    描述 知道requirejs的都知道,每一个页面需要进行模块化开发都得有一个入口js文件进行模块配置.但是现在就有一个很尴尬的问题,如果页面很多的话,那么这个data-main对应的入口文件就会很多. ...

  3. 洛谷P2421 [NOI2002]荒岛野人(扩展欧几里得)

    题目背景 原 A-B数对(增强版)参见P1102 题目描述 克里特岛以野人群居而著称.岛上有排列成环行的M个山洞.这些山洞顺时针编号为1,2,…,M.岛上住着N个野人,一开始依次住在山洞C1,C2,… ...

  4. 洛谷P3199 [HNOI2009]最小圈(01分数规划)

    题意 题目链接 Sol 暴力01分数规划可过 标算应该是这个 #include<bits/stdc++.h> #define Pair pair<int, double> #d ...

  5. 极简】如何在服务器上安装SSL证书?

    本文适合任何人了解,图形化操作.下面以腾讯云为例,并且服务器(linux)也安装了宝塔面板. 1.登陆腾讯云账号进入控制台,找到SSL的产品 2.按要求申请并填写表单,记住私钥密码 3.提交后,待腾讯 ...

  6. Future FutrueTask Callable类源码说明以及原理使用

    1.Future Callable FutureTask 源码说明 JDK内置的Future主要使用到了Callable接口和FutureTask类. Callable是类似于Runnable的接口, ...

  7. Android 自定义弹出框带EditText

    EditText 布局页面 edittext_ownername_dialog.xml: <?xml version="1.0" encoding="utf-8&q ...

  8. codeforces 2B The least round way(DP+数学)

    The least round way 题目链接:http://codeforces.com/contest/2/problem/B ——每天在线,欢迎留言谈论.PS.本题有什么想法.建议.疑问 欢迎 ...

  9. (python)面向对象

    一.面向对象概述 要了解面向对象,就需要先了解面向过程的概念,那么什么是面向过程编程呢?最具代表性的就是C语言了,所谓面向过程编程就是在做一件事的时候,需要按步骤进行,第一步干什么,第二步干什么,这种 ...

  10. 2019年Web前端最新导航(常见前端框架、前端大牛)

    本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 前言 本文列出了很多与前端有关的常见网站.博客.工具等,整体来看比较权威.有些东西已经 ...