博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GCD hdu1695容斥原理
阅读量:6266 次
发布时间:2019-06-22

本文共 3210 字,大约阅读时间需要 10 分钟。

GCD

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5106    Accepted Submission(s): 1833

Problem Description
Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you're only required to output the total number of different number pairs.
Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.
Yoiu can assume that a = c = 1 in all test cases.
 

 

Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 3,000 cases.
Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
 

 

Output
For each test case, print the number of choices. Use the format in the example.
 

 

Sample Input
2 1 3 1 5 1 1 11014 1 14409 9
 

 

Sample Output
Case 1: 9 Case 2: 736427
Hint
For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5106    Accepted Submission(s): 1833

Problem Description
Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you're only required to output the total number of different number pairs.
Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.
Yoiu can assume that a = c = 1 in all test cases.
 

 

Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 3,000 cases.
Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
 

 

Output
For each test case, print the number of choices. Use the format in the example.
 

 

Sample Input
2
1 3 1 5 1
1 11014 1 14409 9
 

 

Sample Output
Case 1: 9
Case 2: 736427
Hint
For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).
 
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 vector
q[110000]; 9 long long a[110000]={ 0};10 int bb;11 void init()12 {13 int i,j;14 for(i=0; i<110000; i++)a[i]=i,q[i].clear();15 for(i=2; i<110000; i+=2)16 a[i]/=2,q[i].push_back(2);17 for(i=3; i<110000; i+=2)18 if(a[i]==i)19 for(j=i; j<110000; j+=i)20 a[j]=a[j]/i*(i-1),q[j].push_back(i);21 for(i=1; i<110000; i++)22 a[i]+=a[i-1];23 }24 int fun(int x,int y)25 {26 int i,cnt=0;27 int sum=1;28 for(i=0;i
d)swap(bb,d);60 if(k)61 bb/=k,d/=k;62 else63 {64 printf("Case %d: %d\n",i,0);65 continue;66 }67 ans=a[bb];68 for(j=bb+1; j<=d; j++)69 {70 ans+=work(j);71 }72 printf("Case %d: %I64d\n",i,ans);73 }74 }
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3682068.html

你可能感兴趣的文章
.NET Entity Framework入门操作
查看>>
iOS-集成微信支付和支付宝支付
查看>>
SAP
查看>>
读掘金小册组件精讲总结2
查看>>
MVC项目中怎样用JS导出EasyUI DataGrid为Excel
查看>>
制作个人开发IDE
查看>>
给架构师骂了
查看>>
ajax提交form表单资料详细汇总
查看>>
Excel——使用INDEX和SMALL实现条件筛选
查看>>
c#迭代器 转载
查看>>
JQuery与JavaScript
查看>>
Jmeter--正则表达式提取器
查看>>
设置Slider Control 控件的取值范围
查看>>
struts2 启动tomcat时报错:org.apache.catalina.core.StandardContext filterStart
查看>>
asp.net导入后台代码
查看>>
java web dev知识积累
查看>>
Flex 经纬度匹配正则表达式
查看>>
在SSIS包中使用 Checkpoint从失败处重新启动包[转]
查看>>
为什么开通博客?
查看>>
深入浅出Mybatis系列(四)---配置详解之typeAliases别名(mybatis源码篇)
查看>>