题意:求解 $$\prod_{1 \leq i \leq n} \prod_{1 \leq j \leq m} {(i,j)}$$

解法:

满脑子的反演

考虑对于第一个质数 $p$ 的贡献为 $p^{[\frac{n}{p}][\frac{m}{p}] + [\frac{n}{p^2}][\frac{m}{p^2}] ... }$

这样1~n的质数大概有$O(\frac{n}{logn})$,对于每一个质数$O(logn)$,总效率大概为 $O(n)$

#include <iostream>
#include <cstdio>
#include <cstring> #define LL long long
#define N 10000010
#define P 1000000007LL using namespace std; int n, m, tot, prime[N];
bool v[N]; LL qpow(LL x, LL n)
{
LL ans = ;
for(; n; n >>= , x = x * x % P)
if(n & )
ans = ans * x % P;
return ans;
} int main()
{
int T;
for(int i = ; i < N; i++)
if(!v[i])
{
prime[++tot] = i;
for(int j = i+i; j < N; j += i)
v[j] = ;
}
scanf("%d", &T);
while(T--)
{
scanf("%d %d", &n, &m);
if(n > m) swap(n, m);
LL ans = ;
for(int i = ; i <= tot; i++)
if(prime[i] <= n)
{
LL tmp = prime[i];
LL cnt = ;
while(tmp <= n)
{
cnt += (n/tmp) * (m/tmp);
tmp *= prime[i];
}
ans = ans * qpow(prime[i], cnt) % P;
}
printf("%lld\n", ans);
}
}

Product it again的更多相关文章

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

  10. LeetCode: Product of Array Except Self

    Dynamic Programming public class Solution { public int[] productExceptSelf(int[] nums) { int[] ans = ...

随机推荐

  1. java监听器演示样例

    监听器的原理是观察者模式.就像明星(事件源)聚拢了一群粉丝(观察者).当明星有啥举动的时候会通过粉丝们报道出去. 订阅信息.计算器button都是该原理的应用. 以下写了一个监听器的小样例: pack ...

  2. PE发送报文

    步骤: 1. 在 action 中使用发送报文,要指定报文在 router 端的交易名称 2. 如果使用 supe.execute(context) 来发送,不需要第一步 3. 配置从网银到 rout ...

  3. C++算法之 一句话推断一个整数是不是2 的整数次方

    思路:一个整数假设是2的整数次方,那么它的二进制表示中有且仅仅有一位是1,而其它全部位都是0.把这个整数与这个整数减去1之后进行与运算.那么这个整数其中唯一的 1会变为0,这个整数也变为0: 代码: ...

  4. SAM4E单片机之旅——4、LED闪烁之PWM

    两个LED灯虽然可以闪了,但是总是需要CPU的参与.现在尝试使用一种更为自动化的方法:让脉宽调制(PWM)控制器输出具有一定周期和占空比的方波,以此控制LED灯的亮灭. 一.实现思路 依然使用蓝色和琥 ...

  5. In Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase.

    https://git-scm.com/book/en/v2/Git-Branching-Rebasing

  6. `npm install`卡住不动,使用`sudo npm install`就可以下载依赖包

    当我在项目中执行npm install的时候,等了几分钟也没有打印信息出来,竟然卡住不动了. 我取消之后再执行sudo npm install发现是可以安装的.只是安装的node_models文件夹不 ...

  7. 如何解决Apache无法启动的问题

    今天重装xampp后,一直无法启动Apache,提示以下错误: 22:36:54 [Apache] Attempting to start Apache app...22:36:54 [Apache] ...

  8. 解决shell脚本“syntax error near unexpected token `fi'”的问题。

    执行shell脚本的时候,提示如下错误: 查询资料后发现: 执行: vi finddir.sh 然后,输入 :set ff 结果是: 解决方案就是,修改为unix: :set ff=unix 执行保存 ...

  9. HZNU 2154 ldh发奖金【字符串】

    题目链接 http://acm.hznu.edu.cn/OJ/problem.php?id=2154 思路 先判断不能拆分的情况 以为需要拆分成两个正整数 所以我们可以知道 只有个位的数字 是不能够拆 ...

  10. 自动化测试框架PatatiumWebUi

    PatatiumWebUi 官网:https://git.oschina.net/zhengshuheng/PatatiumWebUi 这是Java编写的框架,基于Selenium.TestNG等技术 ...