题意:求解 $$\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. python(7)- 小程序练习:循环语句for,while实现99乘法表

    打印99乘法表 for 循环语句实现: for i in range(1,10): for j in range(1,10): print(j,"x",i,"=" ...

  2. springMVC学习之验证

    验证框中@NotEmpty.@NotBlank.@NotNull乍一看还是容易弄混的.主要使用情况记录一下: @NotEmpty 用在集合类上面 @NotBlank 用在String上面 @NotNu ...

  3. Android Volley分析(一)——结构

    Volley是Android系统下的一个网络通信库.为Android提供简单高速的网络操作(Volley:Esay, Fast Networking for Android),以下是它的结构: 既然是 ...

  4. 【每日Scrum】第二天(4.12) TD学生助手Sprint1站立会议

    TD学生助手Sprint1站立会议(4.12) 任务看板 站立会议内容 组员 昨天 今天 困难 签到 刘铸辉 (组长) 做了几个Sqlite编辑事件导入数据库没成功,就编辑图片滑动显示功能 今天学习了 ...

  5. C#.NET开源项目、机器学习、Power BI (转载)

    .NET技术, 开源项目, 数据挖掘, 机器学习, 微软Power BI, 足球赛事分析, Matlab与C#编程 博客园 管理 本站首页 头条推荐 Power BI .NET开源 机器学习 博客美化 ...

  6. 解压 boot.img

    ./split_bootimg.pl boot.img Page size: 2048 (0x00000800) Kernel size: 7062084 (0x006bc244) Ramdisk s ...

  7. 【重磅干货】看了此文,Oracle SQL优化文章不必再看!

    目录 SQL优化的本质 SQL优化Road Map 2.1 制定SQL优化目标 2.2 检查执行计划 2.3 检查统计信息 2.4 检查高效访问结构 2.5 检查影响优化器的参数 2.6 SQL语句编 ...

  8. 《UNIX 环境高级编程》编译环境的搭建( 运行本专栏代码必读 )

    第一步:搭建基本的编译环境 安装gcc, g++, bulid-essential等编译软件 第二步:下载本书示例源码包 可在这里下载 www.apuenook.com 第三步:解压下载到的包并放在用 ...

  9. MySQL 存储过程 (3)

    以下介绍下像数据库循环插入数据操作 第一步:建立存储过程用到的信息表

  10. windows 打开文件夹

    @echo off rem 建立链接 net use \\192.168.2.3\share /user:username password rem 打开共享文件夹 explorer \\192.16 ...