其他分享
首页 > 其他分享> > 洛谷1072:Hankson的趣味题

洛谷1072:Hankson的趣味题

作者:互联网

洛谷1072:Hankson的趣味题

题意:

思路:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a0, b0, a1, b1;

inline int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a%b);
}

inline ll lcm(ll a, ll b){
    return (a*b) / gcd(a,b);
}


inline bool check(int x){
    return gcd(x, a0) == a1 && lcm(x, b0) == b1;
}

inline void solve()
{
    //gcd(x, a0) = a1
    //lcm(x, b0) = b1
    //question: Number of x ?
    scanf("%d%d%d%d", &a0 , &a1, &b0, &b1);
    int ans = 0;
    for(int i = 1; i <= b1/i; i++)
    {
        if(b1 % i == 0)
        {
            ans += check(i) == true;
            if(i * i != b1) ans += check(b1/i) == true;
        }
    } printf("%d\n", ans);
}

int main()
{
    int T; scanf("%d", &T);
    while(T--) solve();
    return 0;
}

标签:洛谷,gcd,int,1072,return,b0,frac,lcm,Hankson
来源: https://www.cnblogs.com/zxytxdy/p/12234779.html