GCD

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

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
题意:在[a,b]里面选一个数x,[c,d]里面选一个数y 使得gcd(x,y)==k,这样的方案有多少个
定义:
f(d)表示gcd(x,y)==k的个数  演化就是gcd(x/k,y/k)==1的个数
F(n)表示gcd(x/k,y/k)==n(t=1,2,3,4,5,...)

可以通过莫比乌斯反演变化为

F(k)=(x/k)*(y/k)

 很明显  根据公式来看  F(d)是已知的,
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
#define eps 1e-10
#define LL unsigned long long
using namespace std;
const int INF=0x3f3f3f3f;
const int N=+;
const int mod=;
ll mu[N];
void getmu(){
ll flag=;
for(int i=;i<N;i++){
if(i==)flag=;
else{
flag=;
}
ll t=flag-mu[i];
mu[i]=t;
for(int j=*i;j<N;j=j+i){
mu[j]=mu[j]+t;
}
}
}
int main(){
int t;
getmu();
//for(int i=1;i<=10;i++)cout<<mu[i]<<" ";
//cout<<endl;
scanf("%d",&t);
int a,b,c,d,k;
int Case=;
while(t--){
int flag=;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
if(k==){
printf("Case %d: ",Case++);
cout<<<<endl;
continue;
}
b=b/k;
d=d/k;
ll ans=;
int minn=min(b,d);
for(int i=;i<=minn;i++){
ans=ans+mu[i]*(b/i)*(d/i);
}
ll ans1=;
for(int i=;i<=minn;i++){
ans1=ans1+(mu[i]*(minn/i)*(minn/i));
}
printf("Case %d: ",Case++);
cout<<ans-ans1/<<endl;
} }

hdu 1695(莫比乌斯反演)的更多相关文章

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

    题意: 从区间[1, b]和[1, d]中分别选一个x, y,使得gcd(x, y) = k, 求满足条件的xy的对数(不区分xy的顺序) 分析: 虽然之前写过一个莫比乌斯反演的总结,可遇到这道题还是 ...

  2. GCD HDU - 1695 莫比乌斯反演入门

    题目链接:https://cn.vjudge.net/problem/HDU-1695#author=541607120101 感觉讲的很好的一个博客:https://www.cnblogs.com/ ...

  3. HDU 4746 (莫比乌斯反演) Mophues

    这道题看巨巨的题解看了好久,好久.. 本文转自hdu4746(莫比乌斯反演) 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<= ...

  4. HDU 5212 莫比乌斯反演

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  5. HDU 6053(莫比乌斯反演)

    题意略. 思路:首先想到暴力去扫,这样的复杂度是n * min(ai),对于gcd = p,对答案的贡献应该是 (a1 / p) * (a2 / p) * .... * (an / p),得出这个贡献 ...

  6. hdu 4746Mophues[莫比乌斯反演]

    Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total ...

  7. 算术 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 ...

  8. HDU 4746 莫比乌斯反演+离线查询+树状数组

    题目大意: 一个数字组成一堆素因子的乘积,如果一个数字的素因子个数(同样的素因子也要多次计数)小于等于P,那么就称这个数是P的幸运数 多次询问1<=x<=n,1<=y<=m,P ...

  9. HDU 5382 莫比乌斯反演

    题目大意: 求S(n)的值 n<=1000000 这是官方题解给出的推导过程,orz,按这上面说的来写,就不难了 这里需要思考的就是G(n)这个如何利用积性函数的性质线性筛出来 作为一个质数,那 ...

随机推荐

  1. css 众妙之门 学习笔记

    伪类: 结构伪类: :empty :only-child :before :after :active :hover :focus :link :visited :first-child :last- ...

  2. (转)Arcgis for javascript实现百度地图ABCD marker的效果

    概述: 在我的博客中,有一篇相关的文章,这段时间,有很多人问我求源码,只是时间过去已长,源代码已找不到,乘着这个9.3放假,又重新实现了下,并相关代码做了优化,在此贴出来,方便大家使用. 相关文章地址 ...

  3. CAD向控件注册一个命令(com接口VB语言)

    主要用到函数说明: MxDrawXCustomFunction::Mx_RegistUserCustomCommand 向控件注册一个命令,用户在命令行输入命令名这个字符串,就会触发执行命令事件 命令 ...

  4. CAD动态绘制多段线(com接口)

    主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY1 直线的开始点y坐标 DOUBLE ...

  5. logback日志配置文件

    application.properties application.properties logback-spring.xml <?xml version="1.0" en ...

  6. cshtml中字符串中表示特殊字符@

    用“@@”表示字符串中的特殊字符@

  7. Django - ORM实现用户登陆

    1.路由分发cmdb(app)下urls.py中,建立url与函数对应关系 2.login.html代码: 3.views.py中,login函数,确认是否登陆成功 备注:从前端 获取用户名,密码,在 ...

  8. 小程序map地图多点定位

    最近需求有一个类似共享单车查看附近单车的功能,看了看小程序map api对多点定位显示描述的不怎么清晰.显示定位数组添加多个时就不显示了.踩了几个坑写了几个方法.最终弄出来了.有问题建议欢迎留言. h ...

  9. (C/C++学习)9.C/C++优化排序

    说明:在C/C++中常见的排序方法有两种,第一种为选择排序法,第二种为冒泡排序法,本文将对这两种排序法进行优化,并给出一种更为快捷的排序法. 一.未优化的排序法 现在假如要对一个数组进行排序,假设这个 ...

  10. python 易忘操作整理

    >>> l=[1,2,3,4,5] >>> s='$'.join(str(i) for i in l) >>> print(s,end=" ...