Skip to content

Instantly share code, notes, and snippets.

@mojaie
Created November 28, 2011 09:44
Show Gist options
  • Save mojaie/1399791 to your computer and use it in GitHub Desktop.
Save mojaie/1399791 to your computer and use it in GitHub Desktop.
AOJ:0005
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNext()) {
int a = scn.nextInt();
int b = scn.nextInt();
int big = 0;
int small = 0;
if (a > b) {
big = a;
small = b;
} else {
big = b;
small = a;
}
int gcd = 0;
while (true) {
int r = big % small;
if (r != 0) {
big = small;
small = r;
} else {
gcd = small;
break;
}
}
long lcm = a * b / gcd;
System.out.println(gcd + " " + lcm);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment