#10213: 最大公因數(GCD) 求解ˊˋ


andy602602 (璽睿)


import java.util.*;

public class Fu {

    public static void main(String[] args) 

    {

    Scanner sc = new Scanner(System.in);

    while(sc.hasNext()){

    int a=0,b=0;

    a=sc.nextInt();

    b=sc.nextInt();

    if(a<=0)System.out.println(0);

    else

    if(b<=0)System.out.println(0);

    else

    System.out.println(G(a,b)+ " ");

    }

    }

    static int G(int a,int b)

    {

    if (a<=0) return b ;

    if (b<=0) return a;

    return ((a>b)?(G(a-b,b)):(G(b-a,a)));

    }

}

以上是程式碼.各種測試都是過了可是 是WA 無窮迴圈..試了二十幾次都過不了第一測試點...

謝謝幫忙.