a738: 最大公约数

題目:http://zerojudge.tw/ShowProblem?problemid=a738
程式碼:

import java.util.Scanner;
public class a738 {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner sc = new Scanner(System.in);
  while(sc.hasNext()){
   int a = sc.nextInt();
   int b = sc.nextInt();
   int t = 0;
   while(a%b!= 0){
     t = a % b;
     a = b;
     b = t;
   }
    System.out.println(b);
  }

 }

}

留言

熱門文章