Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created May 4, 2015 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerioagjr/1a79124ba6c7bd2afe0b to your computer and use it in GitHub Desktop.
Save rogerioagjr/1a79124ba6c7bd2afe0b to your computer and use it in GitHub Desktop.
Mini-Calculadora - Java
import java.util.Scanner;
public class solucao {
public static int mdc(int a,int b){
int r;
while(true){
r = a % b;
if(r == 0)break;
a = b;
b = r;
}
return b;
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n,a,b;
n = in.nextInt();
a = in.nextInt();
b = in.nextInt();
int r = mdc(a,b);
a /= r;
b /= r;
if(n > a && n > b){
System.out.printf("%d %d\n",a,b);
}
else System.out.println("IMPOSSIVEL\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment