GCD

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

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).

 
Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define esp 0.00000000001
#define pi 4*atan(1)
const int N=1e5+,M=1e7+,inf=1e9+,mod=1e9+;
int mu[N], p[N], np[N], cnt, sum[N];
void init() {
mu[]=;
for(int i=; i<N; ++i) {
if(!np[i]) p[++cnt]=i, mu[i]=-;
for(int j=; j<=cnt && i*p[j]<N; ++j) {
int t=i*p[j];
np[t]=;
if(i%p[j]==) { mu[t]=; break; }
mu[t]=-mu[i];
}
}
}
int main()
{
int T,cas=;
init();
scanf("%d",&T);
while(T--)
{
int a,b,c,d,k;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
if(k==)
{
printf("Case %d: 0\n",cas++);
continue;
}
b/=k,d/=k;
if(b>=d)swap(b,d);
ll ans=;
for(int i=;i<=b;i++)
{
ans+=(ll)mu[i]*(b/i)*(d/i);
}
ll ans2=;
for(int i=;i<=b;i++)
{
ans2+=(ll)mu[i]*(b/i)*(b/i);
}
printf("Case %d: %lld\n",cas++,ans-ans2/);
}
return ;
}

hdu 1695 GCD 莫比乌斯的更多相关文章

  1. hdu 1695 GCD 莫比乌斯反演入门

    GCD 题意:输入5个数a,b,c,d,k;(a = c = 1, 0 < b,d,k <= 100000);问有多少对a <= p <= b, c <= q <= ...

  2. HDU 1695 GCD 莫比乌斯反演

    分析:简单的莫比乌斯反演 f[i]为k=i时的答案数 然后就很简单了 #include<iostream> #include<algorithm> #include<se ...

  3. D - GCD HDU - 1695 -模板-莫比乌斯容斥

    D - GCD HDU - 1695 思路: 都 除以 k 后转化为  1-b/k    1-d/k中找互质的对数,但是需要去重一下  (x,y)  (y,x) 这种情况. 这种情况出现 x  ,y ...

  4. HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 1695 GCD (莫比乌斯反演)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. HDU 1695 GCD (莫比乌斯反演模板)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  7. hdu 1695 GCD 【莫比乌斯函数】

    题目大意:给你 a , b , c , d , k 五个值 (题目说明了 你可以认为 a=c=1)  x 属于 [1,b] ,y属于[1,d]  让你求有多少对这样的 (x,y)满足gcd(x,y)= ...

  8. hdu 1695: GCD 【莫比乌斯反演】

    题目链接 这题求[1,n],[1,m]gcd为k的对数.而且没有顺序. 设F(n)为公约数为n的组数个数 f(n)为最大公约数为n的组数个数 然后在纸上手动验一下F(n)和f(n)的关系,直接套公式就 ...

  9. hdu 1695 GCD(莫比乌斯反演)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

随机推荐

  1. 一张图玩转H5测试

    背景 随着各种H5页面的普及和运用,并深深的影响着我们各个业务的发展,前两年也对H5测试的有着不少积累,但都是根据项目的要求,这里测试下,那里测试下,今年上半年专门成立了H5测试研究虚拟小组,专门研究 ...

  2. 2318: Spoj4060 game with probability Problem

    2318: Spoj4060 game with probability Problem Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 356  Sol ...

  3. 普通java工程的resources目录寻址

    问题: 普通java工程的src/main/resources目录下的配置文件如何寻址 在src/main/java目录下的代码中如何访问src/main/resources目录下的配置文件? Mav ...

  4. Brouwer fixed-point theorem

    w https://en.wikipedia.org/wiki/Brouwer_fixed-point_theorem https://zh.wikipedia.org/wiki/布劳威尔不动点定理 ...

  5. QBuffer简单操作(被看做一个标准的可随机访问的文件,支持信号)

    Qt中通过QBuffer类我们可以使用io的方式访问.操作QByteArray中的内容.此时,QByteArray被看做一个标准的可随机访问的文件.例如: QBuffer buffer; char c ...

  6. 使用nose_parameterized使unitTest实现参数化

    nose-parameterized是一个针对Python单元测试框架实现参数化的扩展 import unittest # from nose_parameterized import paramet ...

  7. Dockerfile学习(二)

    这节学习制作一个ssh镜像服务. 创建sshtest目录,进入到该目录中. 假如允许主机B上的root用户可以通过SSH登录到容器内部,那么首先要在B主机上通过ssh-keygen -t rsa命令生 ...

  8. 玩转NumPy数组

    一.Numpy 数值类型 1.前言:Python 本身支持的数值类型有 int(整型, long 长整型).float(浮点型).bool(布尔型) 和 complex(复数型).而 Numpy 支持 ...

  9. Java进阶学习:将文件上传到七牛云中

    Java进阶学习:将文件上传到七牛云中 通过本文,我们将讲述如何利用七牛云官方SDK,将我们的本地文件传输到其存储空间中去. JavaSDK:https://developer.qiniu.com/k ...

  10. Linux常用的指令(...编辑文件+保存)

    mkdir命令用来创建目录 1 mkdir filename touch命令有两个功能:一是用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来:二是用来创建新的 ...