codeforces 992B

Nastya Studies Informatics
题目
Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.
题意
给你4个数l,r,x,y;x,y,分别代表的是最大公约数和最小公倍数题目让你求在l到r之间有多少对满足最大公约数是x最小公倍数是y的数目,(a,b)和(b,a)表示不同对,只有a=b时候才表示一对
题解
我们可以先设两个函数 A和B ,A和B可以分解为 A=xn,B=xm;然后我们根据最小共倍数与最大公约数之间的关系我们可得nm=y/x;然后我们就可以枚举1到根号nm的数字只要她满足其规律即可。
代码

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int gcd(int a,int b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
int main()
{
  int l,r,x,y;
  int tem;int ans=0;
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin>>l>>r>>x>>y;
  tem=y/x;
    if(y%x){cout<<"0"<<endl;return 0;} 
 for(int i=1;i*i<=tem;i++)
 {
   int j=tem/i;
   if(tem%i==0&&gcd(i,j)==1&&i*x>=l&&i*x<=r&&j*x>=l&&j*x<=r)
       ans+=i==j?1:2;

 }
 cout<<ans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值