UVA 11417 Java
import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int num; while((num = sc.nextInt()) != 0) { int gcd = 0; for(int i = 1; i < num; i++) for(int j = i+1; j <= num; j++) { int num1 = i, num2 = j; while(num2 != 0) { int temp = num2; num2 = num1 % num2; num1 = temp; } gcd += num1; } System.out.println(gcd); } } };
留言
張貼留言