Skip to content

Instantly share code, notes, and snippets.

@folivetti
Created March 6, 2017 12:50
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 folivetti/0b650349612ec15b42b164be5506c369 to your computer and use it in GitHub Desktop.
Save folivetti/0b650349612ec15b42b164be5506c369 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static int gcd (int x, int y) {
int r = x%y;
while (r!=0) {
x = y;
y = r;
r = x%y;
}
return y;
}
public static int gcd3(int x, int y, int z) {
return gcd(x, gcd(y,z));
}
public static void main(String[] args) throws IOException {
int x, y, z, tmp;
String linha;
Scanner leitor = new Scanner(System.in);
while (leitor.hasNextLine()) {
linha = leitor.nextLine();
if (linha == null) break;
Scanner sc = new Scanner(linha);
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
// x tem o maior valor
if (y > x && y >= z) {
tmp = x;
x = y;
y = tmp;
} else if (z > x && z > y) {
tmp = x;
x = z;
z = tmp;
}
System.out.print("tripla");
if (x*x == (y*y + z*z)) {
System.out.print(" pitagorica");
if (gcd3(x,y,z) == 1) {
System.out.print(" primitiva");
}
}
System.out.println("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment