题意:求解 $$\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);
}
}

最新文章

  1. SpringMVC -- 注解
  2. DropDownList控件
  3. 各大搜索引擎智能提示API(JSONP跨域实现自动补全搜索建议)
  4. JavaScript-cookie是客户端本地,持久存储用户私密数据的文件
  5. HTML5使用ApplicationCache
  6. tmux 快捷键
  7. Min Stack
  8. online ddl 工具之pt-online-schema-change
  9. CSS遮罩——如何在CSS中使用遮罩
  10. [Objective-c 基础 - 2.1] 封装
  11. qt优点
  12. swing JTable
  13. ES6优缺点
  14. 【转载】Latex定制章节编号格式和计数器
  15. Guava:好用的java类库 学习小记
  16. 05-树9 Huffman Codes及基本操作
  17. TCP如何保证可靠性
  18. css案例 - mask遮罩层的华丽写法
  19. 解决错误:Couldn&#39;t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  20. Thinkphp3.2版本Controller和Action的访问方法

热门文章

  1. 【转载】Web Service和WCF的到底有什么区别
  2. PHP读取远程文件的4种方法
  3. 网页编程-Django(一)
  4. 2017-07-19-CR 和 LF
  5. mac osx 下编译 OpenWrt
  6. BZOJ 2818 Gcd 线性欧拉
  7. MongoDB之增删改查(一)
  8. 兼容最新firefox、chrome和IE的javascript图片预览实现代码
  9. STM32 ~ 查看系统时钟
  10. ffmpeg 的一些学习网站