Product it again
题意:求解 $$\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的更多相关文章
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [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 ...
- [LeetCode] Maximum Product Subarray 求最大子数组乘积
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- vector - vector product
the inner product Givens two vectors \(x,y\in \mathbb{R}^n\), the quantity \(x^\top y\), sometimes c ...
- 1 Maximum Product Subarray_Leetcode
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Leetcode Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- 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 ...
- [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 ...
- sp_addlinkedserver '(null)' is an invalid product name
使用SSMS 2008客户端工具逆向生成了创建链接服务器的脚本时,在测试环境执行是报如下错误:'(null)' is an invalid product name. USE [master] GO ...
- LeetCode: Product of Array Except Self
Dynamic Programming public class Solution { public int[] productExceptSelf(int[] nums) { int[] ans = ...
随机推荐
- jvm基础(1)
1.整型数和浮点型数的表示 原码:第一位为符号位(0为正数,1为负数). 反码:符号位不动,源码取反. 正数补码:和原码相同. 负数补码:符号位不动,反码加1. 例如5的二进制表示可以是0000010 ...
- 5分钟部署filebeat + ELK 5.1.1
标题有点噱头,不过网络环境好的情况下也差不多了^_^ 1. 首先保证安装了jdk. elasticsearch, logstash, kibana,filebeat都可以通过yum安装,这里前 ...
- Linux高端内存
Linux高端内存是针对物理内存来说的,虚拟内存没有高端这个概念.Linux系统将虚拟内存分为两个部分,即用户地 址空间和内核地址空间,对于32位系统来说,虚拟地址空间为4GB,其中用户空间范围为0- ...
- KMP算法模式匹配
转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/37832707 作者:小马 在一个长串中查找一个子串是较经常使用的操作.各种信息检索 ...
- poj 1163 The Triangle &poj 3176 Cow Bowling (dp)
id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...
- Mvc Autofac构造器注入
新建MVC项目,添加程序集引用 定义接口ILog public interface ILog { string Save(string message); } 类TxtLog实现接口ILog publ ...
- [转]***换机房换ip之后不能连外网
***换机房换ip之后不能连外网 时间 2015-07-21 15:17:16 Wendal随笔 原文 http://wendal.net/2015/07/21.html 主题 iptables ...
- 在VC++空工程中使用MFC类,采用Unicode字符集后,运行工程程序报错的解决方案
创建一个VC++空工程,将Project Properties->General->Use of MFC改为Use MFC in a Shared DLL 新建一个源文件,内容如下 #in ...
- 6.JS输出
JavaScript 通常用于操作 HTML 元素. ① document.getElementById(id),可以访问某个 HTML 元素 请使用 "id" 属性来标识 HTM ...
- assign,copy,strong,weak,nonatomic的具体理解
例子: NSString *houseOfMM = [[NSString alloc] initWithString:'MM的三室两厅']; 上面一段代码会执行以下两个动作: 1 在堆上分配一段内存 ...