andy6804tw
8/1/2016 - 6:46 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=13352 這題先取三個數的最大公因數例如:500 15 5 3 gcd(15 5 3)=15 15/15*15/5*15/3=1*3*5=15<=50

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=13352

這題先取三個數的最大公因數例如:500 15 5 3 gcd(15 5 3)=15 15/1515/515/3=135=15<=500 30/1530/530/3=2610=120<=500 45/1545/545/3=3915=405 (下一筆超過500所以取到這裡)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		while (count-- != 0) {
			int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), i = 0, temp = 0, j = 0;
			for (i = 2; i <= a * b * c; i++) {
				if (i % a == 0 && i % b == 0 && i % c == 0)
					break;
			}
			for (j = 1; j <= n; j++) {
				int num = i * j, tot = 0;
				tot = (num / a) * (num / b) * (num / c);
				if (tot > n)
					break;
				temp = tot;
			}
			if (temp == 0)
				System.out.println("No solution");
			else
				System.out.println(temp);
		}
	}
   /* 題目:[C_GM16-易] 堆積木
    作者:1010
    時間:西元 2016 年 8 月 */
}