(Relax 数论 1.1)POJ 2429 GCD & LCM Inverse(已知GCD、LCM,反求a、b)

import java.math.BigInteger;
import java.util.Scanner;

public class POJ_2429 {

	static long gcd(long a, long b) {
		long tmp;
		while (b != 0) {
			a %= b;
			tmp = a;
			a = b;
			b = tmp;
		}
		return a;
	}

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

		long a;
		long b;
		long c;
		while (scanner.hasNext()) {
			a = scanner.nextLong();
			b = scanner.nextLong();

			c = b / a;

			long i;
			for (i = (long) Math.sqrt(c); i >= 1; --i) {
				if (c % i == 0 && gcd(i, c / i) == 1) {
					System.out.println(a*i +" " + b/i);

					break;
				}
			}
		}
	}
}

你可能感兴趣的:((Relax 数论 1.1)POJ 2429 GCD & LCM Inverse(已知GCD、LCM,反求a、b))