50分求优化!!!(@_@)
查看原帖
50分求优化!!!(@_@)
373226
justinjia楼主2021/1/11 11:26
R44845349 记录详情\colorbox{black}{R44845349 记录详情} 测试点信息\text{测试点信息} \#1&\#2&\#3&\#4&\#5&\#6&\#7&\#8&\#9&\#10\\ \color{white}\colorbox{green}{AC}&\color{white}\colorbox{darkblue}{TLE}&\color{white}\colorbox{green}{AC}&\color{white}\colorbox{green}{AC}&\color{white}\colorbox{green}{AC}&\color{white}\colorbox{green}{AC}&\color{white}\colorbox{darkblue}{TLE}&\color{white}\colorbox{darkblue}{TLE}&\color{white}\colorbox{darkblue}{TLE}&\color{white}\colorbox{darkblue}{TLE} \end{matrix}$$ $$\color{lightblue} \text{源代码}
#include"stdio.h"
#include"algorithm"
using namespace std;
int gcd(int a,int b){
    if(!b)
        return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int main(void){
    int n,a0,a1,b0,b1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int ans=0;
        scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
        for(int x=1;x<=b1;x++)//根据第2个条件,x的范围应该在1~b1
            if(gcd(min(x,a0),max(x,a0))==a1&&lcm(min(x,b0),max(x,b0))==b1)
                ans++;
        printf("%d\n",ans);
    }
    return 0;
}
2021/1/11 11:26
加载中...