2 6 2 12 4
4 8
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int n = input.nextInt(); for(int i=0;i<n;i++) { int a = input.nextInt(); int b = input.nextInt(); for(int j=2;j<1000000;j++) { if(b==GCD(a,b*j)) { System.out.println(b*j); break; } } } } public static int GCD(int a,int c) { if(a<c) { return GCD(c,a); } if(a%c!=0) { return GCD(c, a%c); } else { return c; } } }
原文地址:http://blog.csdn.net/qq_16542775/article/details/45439505