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. 七、Dockerfile案例三(Mysql安装)

    七.Dockerfile案例三(Mysql安装) *特别提醒:新版的mysql:5.7数据库下的user表中已经没有Password字段了(5.5的user表还有) 一.查看docker hub上的版 ...

  2. 企业实施DevOPS的七大挑战(转)

    从别人的演讲视频中摘抄,做笔记. 什么是DevOPS 如何衡量DevOPS 企业实施DevOPS的七大挑战 自动化测试投入不足 单元测试 API测试 界面测试 功能测试 高度集中的IT服务 标准化 脚 ...

  3. dfs-求连通块

    状态:若为W则继续搜索 import java.util.Scanner; public class Main { static int n,m; static char[][] field; sta ...

  4. Pycharm中目前用到的快捷键

    1.批量注释:Ctrl+/ 2.缩进\不缩进:Tab\Shift+Tab 3.运行:Ctrl+Shift+F10 4.撤销\反撤销:Ctrl+z\Ctrl+shift+z 5.当光标在代码中间,如何回 ...

  5. crontab 问题分析 - CSDN博客 https://blog.csdn.net/tengdazhang770960436/article/details/50997297

    cd /mnt/tools/trunk/plugins/personas; python update_keywords.py crontab 问题分析  crontab 问题分析 - CSDN博客 ...

  6. 我的Android进阶之旅------>百度地图学习:BDLocation.getLocType ( )值分析

    BDLocation类,封装了定位SDK的定位结果,在BDLocationListener的onReceive方法中获取.通过该类用户可以获取error code,位置的坐标,精度半径等信息.具体方法 ...

  7. git原理:提交原理

    当运行git add  git commit的时候,git底层都做了什么? 这里涉及到的底层命令:git hash-object 讲对象写入到git object中git update-index   ...

  8. Linux中的grep和cut

    提取行: grep --color  着色 -v         不包含 提取列: cut -f      列号 提取第几列 -d     分隔符 以什么为分隔符,默认是制表键 局限性:如果分隔符不那 ...

  9. [LeetCode-21]Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...

  10. sublime使用心得

    1.ctrl + shift +p 命令面板 ---> toggle_side_bar 2.ctrl + shift +p 命令面板 --->reindent lines 3.ctrl + ...