zoukankan      html  css  js  c++  java
  • Nastya Studies Informatics CodeForces

    B. Nastya Studies Informatics
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    We define a pair of integers (a, b) good, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common divisorof a and b, and LCM(a, b) denotes the least common multiple of a and b.

    You are given two integers x and y. You are to find the number of good pairs of integers (a, b) such that l ≤ a, b ≤ r. Note that pairs (a, b) and (b, a) are considered different if a ≠ b.

    Input

    The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).

    Output

    In the only line print the only integer — the answer for the problem.

    Examples
    input
    1 2 1 2
    output
    2
    input
    1 12 1 12
    output
    4
    input
    50 100 3 30
    output
    0
    Note

    In the first example there are two suitable good pairs of integers (a, b): (1, 2) and (2, 1).

    In the second example there are four suitable good pairs of integers (a, b): (1, 12), (12, 1), (3, 4) and (4, 3).

    In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition l ≤ a, b ≤ r.

    题意:在一个区间里找有序对数,使得最大公约数和最小公倍数为题目所给

    题解:大数 爆搜会超时,先化个简

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<sstream>
    #include<cmath>
    #include<cstdlib>
    #include<queue>
    #include<map>
    using namespace std;
    #define INF 0x3f3f3f3f
    const int maxn=200005;
    
    int gcd(int a,int b)
    {
        if(b==0)
            return a;
        return gcd(b,a%b);
    }
    int main()
    {
        int l,r,x,y,i,num,ans=0;
        cin>>l>>r>>x>>y;
        num=y/x;
        if(y%x!=0)
        {
            cout<<"0"<<endl;
            return 0;
            
        }//num=n*z
        for(i=1;i*i<=num;i++)
        {
            int j=num/i;
            if(num%i==0&&gcd(i,j)==1&&l<=i*x&&i*x<=r&&l<=j*x&&j*x<=r)
            {
                if(i==j)
                    ans=ans+1;
                else
                    ans=ans+2;
            }
        }     
        cout<<ans<<endl;
    }
  • 相关阅读:
    随机数
    质数
    猜数
    失败
    判断质数
    2019.7.21记录
    9*9乘法表
    小人
    奔跑的字母

  • 原文地址:https://www.cnblogs.com/smallhester/p/9499805.html
Copyright © 2011-2022 走看看