LUOGU P1072 Hankson 的趣味题

题目:https://www.luogu.org/problemnew/show/P1072#sub

题解:https://www.luogu.org/problemnew/solution/P1072

https://www.luogu.org/problemnew/solution/P1072

https://www.luogu.org/blog/Kesdiael3/solution-p1072

http://blog.csdn.net/nuclearsubmarines/article/details/77603154

 

初高中生逼死人系列

 

#include <cstdio>
#include <cmath>
using namespace std;

int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}

int main(){

    int n,a0,a1,b0,b1,ans,m;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        ans=0;
        scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
        m=sqrt(b1+1);
        for (int i=a1;i<=m;i+=a1){
            if (gcd(i,a0)==a1&&gcd(i,b0)*b1==b0*i) ans++;
        }
        printf("%d\n",ans);
    }
}

一半数据被卡住。

 

posted @ 2018-02-16 23:53  Travelller  阅读(95)  评论(0编辑  收藏  举报