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 ;
}

最新文章

  1. Android RecyclerView 实现支付宝首页效果
  2. Programming Entity Framework 翻译(2)-目录2-章节
  3. dedecms /install/index.php.bak Installation File Not Deleted &amp;&amp; Executed Via Apache Analytic Vul
  4. linux下安装使用libuuid(uuid-generate)
  5. 【POJ2949】Word Rings(最大平均值环)
  6. iOS:堆(heap)和栈(stack)的理解
  7. WT588D播放合成语音时出现某些语句不能正常播报的情况,经过对比其他语句,看似有点不符合逻辑。
  8. TypeScript学习笔记(五):接口
  9. C#中thrift 中THttpHandler 传输数据 慢 slow 解决办法
  10. java多线程编程(1) 线程的基本知识
  11. [zz]android的logcat详细用法
  12. storm-kafka教程
  13. WEB典型应用
  14. linkin大话面向对象--抽象类
  15. Spring Security(三十三):10.3 Password Encoding
  16. 基于百度API+Flask实现网页版和图灵机器聊天
  17. Kali 2.0 Web后门工具----WebaCoo、weevely、PHP Meterpreter
  18. WPF 重写ListBox(透明效果)
  19. Django 学习笔记(五) --- Ajax 传输数据
  20. MVC ---- T4(1)

热门文章

  1. java使用javax.mail进行免费的邮件发送
  2. 两个大数组foreach,找出相同的key数量,所用的时间对比
  3. 【DL】物体识别与定位
  4. Nginx 向客户端输出真实的后端IP地址
  5. logstash结合rsyslog,收集系统日志
  6. vue-resource和vue-axios的简单使用方法
  7. 子窗口访问父页面iframe中的iframe,top打开的子窗口访问父页面中的iframe中的iframe
  8. 【NodeJS】http-server.cmd
  9. windows防火墙设置端口开放技巧
  10. Install VMware Workstation as a Service