我不明白我在哪里做错了。这是扩展gcd(UVa 10104)的UVa问题

时间:2019-05-08 20:47:16

标签: java grand-central-dispatch

与提交的代码相比,我的代码未按预期运行。为什么它们工作方式不同?

提交的代码:

final

我的代码:

 static int x, y;

 static int extendedEuclid(int a, int b) {
     if (b == 0) {
         x = 1;
         y = 0;
         return a;
     }
     int d = extendedEuclid(b, a % b);
     int x1 = y;
     int y1 = x - a / b * y;
     x = x1;
     y = y1;
     return d;
 }

 public static void main(String[] args) throws IOException {
     Scanner sc = new Scanner(System.in);

     PrintWriter out = new PrintWriter(System.out);


     while (sc.hasNextInt()) {
         int a = sc.nextInt(), b = sc.nextInt();
         int d = extendedEuclid(a, b);
         out.printf("%d %d %d\n", x, y, d);
         out.flush();
     }


 }

0 个答案:

没有答案