hdu 4746Mophues[莫比乌斯反演]
Mophues
  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others)
Total Submission(s): 1669    Accepted Submission(s): 675
 
Problem Description
As we know, any positive integer C ( C >= 2 ) can be written as the multiply of
some prime numbers:
    C = p1×p2× p3× ... × pk
which p1, p2 ... pk are all prime numbers.For example, if C = 24, then:
    24 = 2 × 2 × 2 × 3
    here, p1 = p2 = p3 = 2, p4 = 3, k = 4
Given two integers P and C. if k<=P( k is the number of C's prime factors), we
call C a lucky number of P.
Now, XXX needs to count the number of pairs (a, b), which 1<=a<=n , 1<=b<=m, and
gcd(a,b) is a lucky number of a given P ( "gcd" means "greatest common
divisor").
Please note that we define 1 as lucky number of any non-negative integers
because 1 has no prime factor.
Input
The first line of input is an integer Q meaning that there are Q test cases.
Then Q lines follow, each line is a test case and each test case contains three
non-negative numbers: n, m and P (n, m, P <= 5×105.
Q <=5000).
Output
For each test case, print the number of pairs (a, b), which 1<=a<=n , 1<=b<=m,
and gcd(a,b) is a lucky number of P.
Sample Input
2
10 10 0
10 10 1
Sample Output
63
93
Source
2013 ACM/ICPC Asia Regional Hangzhou Online
Recommend
liuyiding | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
//Source:http://acm.hdu.edu.cn/showproblem.php?pid=4746
Description(题意): 
任何整数C
( C >= 2 )都可以写成素数之积
C = p1×p2×
p3×
... × pk
其中, p1, p2 ... pk 是素数。如
C = 24, 则
24 = 2 ×
2 × 2
× 3,
其中, p1 = p2 = p3 = 2, p4 = 3, k = 4.
给定两整数 P和 C,
若 k<=P ( k是
C的素因子个数),称
C是P的幸运数.
现小X需计算的点对 (a,
b)的个数,其中1<=a<=n
, 1<=b<=m, gcd(a,b)是 P的幸运数
( “gcd”是最大公因数).
注意:因为1无素因子,定义1为任何非负数的幸运数.
Input
首行有一个整数
T,表示有 T 组测试数据.接下来有T行,每行是一种测试数据,含3个非负整数n,
m 与P (n, m, P <= 5×105.
T <=5000).
Output
对每种测试数据,输出对
(a, b)的个数,其中 1<=a<=n , 1<=b<=m,
且 gcd(a,b)
是 P的幸运数.
Sample
Input
2
10 10 0
10 10 1
Sample
Output
63
93

//num[j]记录j的因子数。
//g[j][num[i]]用于计算具有相同个数的素因子的i的?(j/i)之和,
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int M=5e5+,N=;
int n,m,p,T,g[M][N],num[M];
int tot,prime[M/],mu[M];bool check[M];
int calc(int y,int x){
int res=;
while(!(y%x)) y/=x,res++;
return res;
}
void sieve(){
n=5e5;mu[]=;
for(int i=;i<=n;i++){
if(!check[i]) prime[++tot]=i,mu[i]=-;
for(int j=;j<=tot&&i*prime[j]<=n;j++){
check[i*prime[j]]=;
if(!(i%prime[j])){mu[i*prime[j]]=;break;}
else mu[i*prime[j]]=-mu[i];
}
}
for(int i=;i<=n;i++) if(!num[i]) for(int j=i;j<=n;j+=i) num[j]+=calc(j,i);
for(int i=;i<=n;i++) for(int j=i;j<=n;j+=i) g[j][num[i]]+=mu[j/i];
for(int i=;i<=n;i++) for(int j=;j<;j++) g[i][j]+=g[i][j-];
for(int i=;i<=n;i++) for(int j=;j<;j++) g[i][j]+=g[i-][j];
}
ll solve(int n,int m,int p){
if(p>=) return 1LL*n*m;
if(n>m) swap(n,m);
ll ans=;
for(int i=,pos=;i<=n;i=pos+){
pos=min(n/(n/i),m/(m/i));
ans+=1LL*(n/i)*(m/i)*(g[pos][p]-g[i-][p]);
}
return ans;
}
int main(){
sieve();
for(scanf("%d",&T);T--;){
scanf("%d%d%d",&n,&m,&p),
printf("%I64d\n",solve(n,m,p));
}
return ;
}
hdu 4746Mophues[莫比乌斯反演]的更多相关文章
- HDU 4746 (莫比乌斯反演) Mophues
		
这道题看巨巨的题解看了好久,好久.. 本文转自hdu4746(莫比乌斯反演) 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<= ...
 - HDU 1695 (莫比乌斯反演) GCD
		
题意: 从区间[1, b]和[1, d]中分别选一个x, y,使得gcd(x, y) = k, 求满足条件的xy的对数(不区分xy的顺序) 分析: 虽然之前写过一个莫比乌斯反演的总结,可遇到这道题还是 ...
 - GCD HDU - 1695   莫比乌斯反演入门
		
题目链接:https://cn.vjudge.net/problem/HDU-1695#author=541607120101 感觉讲的很好的一个博客:https://www.cnblogs.com/ ...
 - HDU 5212 莫比乌斯反演
		
Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
 - hdu 1695(莫比乌斯反演)
		
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
 - HDU 6053(莫比乌斯反演)
		
题意略. 思路:首先想到暴力去扫,这样的复杂度是n * min(ai),对于gcd = p,对答案的贡献应该是 (a1 / p) * (a2 / p) * .... * (an / p),得出这个贡献 ...
 - 算术 HDU - 6715 (莫比乌斯反演)
		
大意: 给定$n,m$, 求$\sum\limits_{i=1}^n\sum\limits_{j=1}^m\mu(lcm(i,j))$ 首先有$\mu(lcm(i,j))=\mu(i)\mu(j)\m ...
 - HDU 4746 莫比乌斯反演+离线查询+树状数组
		
题目大意: 一个数字组成一堆素因子的乘积,如果一个数字的素因子个数(同样的素因子也要多次计数)小于等于P,那么就称这个数是P的幸运数 多次询问1<=x<=n,1<=y<=m,P ...
 - HDU 5382 莫比乌斯反演
		
题目大意: 求S(n)的值 n<=1000000 这是官方题解给出的推导过程,orz,按这上面说的来写,就不难了 这里需要思考的就是G(n)这个如何利用积性函数的性质线性筛出来 作为一个质数,那 ...
 
随机推荐
- u3d静态函数
			
using UnityEngine; using System.Collections; public class Manager : MonoBehaviour { private static M ...
 - u3d资源打包只能打包场景材质,不能打包脚本
			
GameObject附带脚本打包进来以后,只有一个脚本名字,估计只是关联了脚本,内容却不在,所以后面打包资源的话,一定要把脚本,shader之类的,放到工程目录下
 - UNIX环境编程学习笔记(28)——多线程编程(三):线程的取消
			
lienhua342014-11-24 1 取消线程 pthread 提供了pthread_cancel 函数用于请求取消同一进程中的其他线程. #include <pthread.h> ...
 - windows下caffe安装配置、matlab接口
			
一.CommonSettings.props caffe下载后解压.源代码文件夹caffe-master,到该文件夹下的windows文件夹下,将CommonSettings.props.exampl ...
 - 百度云高速下载Pandownload
			
对于一些文件大小比较小的文件,可以直接在网页分享中点击[下载]来下载: 但是,对于较大点的文件,点击[下载]会弹出百度云的桌面客户端软件来下载: 但但是,下载速度实在是太慢了,强迫症真真等不及啊~ 幸 ...
 - 既使用maven又使用lib下的Jar包
			
maven 使用本地包 lib jar包 依赖一个lib目录 解决方法: # 把本地的lib加入maven编译时的依赖路径 From:http://blog.chinaunix.net/uid-231 ...
 - alsa wav
			
wav_parser.h文件: //File : wav_parser.h //Author : Loon <sepnic@gmail.com> #ifndef __WAV_PARSER_ ...
 - POJ1159——Palindrome
			
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 53647 Accepted: 18522 Desc ...
 - 解压安装的tomcat, 使用chkconfig命令让tomcat 随机启动,tomcat 变为系统服务
			
使用解压安装的tomcat包,命令行输入 service tomcat start 会报 tomcat: unrecognized service 错误提示,意思是说系统没有找到该服务. 好了,我们现 ...
 - ios开发之--NSNumber的使用
			
什么是NSNumber? NSArray/NSDictionary中只能存放oc对象,不能存放基本数据类型,如果想把基本数据类型放进去,需要先把基本数据类型转换成OC对象, 代码如下: ; ; flo ...