請問第97個測資是什麼? 為什麼答案是0? 是a=0嗎?
還有請問k=0的時候就直接是輸出0還是?
以下是我的程式碼
#include<cstdio>
long long gcd(long long a,long long b){
return (b==0?a:gcd(b,a%b));
}
long long judge(long long x,long long y,long long GCD){
if(x%y==0&&x>=y&&GCD>1) printf("%lld\n",(int)x/y);
else if(y==1) printf("%lld\n",x);
else printf("%lld / %lld\n",(x/GCD),(y/GCD));
}
int main(){
long long k,a,b,pi;
while(~scanf("%lld%lld%lld",&k,&a,&b))
{
if(k==0) continue;
if(a==0&&b>0) printf("0\n0\n0\n");
else if(a>0&&b==0)
{
for(int i=0;i<3;i++)
judge(k,4,gcd(k,4));
}
else if(a>0&&b>0)
{
pi=gcd(a,b);
a/=pi,b/=pi;
long long GCD,x,y;
x=(k*a*a),y=2*(a+b)*(2*a+b);
GCD=gcd(x,y);
judge(x,y,GCD);
x=k*a,y=4*a+2*b;
GCD=gcd(x,y);
judge(x,y,GCD);
x=k*(a+b);
GCD=gcd(x,y);
judge(x,y,GCD);
}
}}