贴个Java的
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int res = 0; for(int i = 1; i<= N -1;i++) { for(int j = i ; j<= N-1;j++) { if(!huZhi(i,j)) { continue; } for(int k = j; k <=N; k++) { if(k*k - i*i - j*j > 0) { break; } else if(k*k - i*i - j*j < 0) { continue; } if(!huZhi(i, k) || !huZhi(j, k)) { break; }
res++; }
}
}
System.out.println(res); } public static boolean huZhi(int a, int b) { while(a!=0) { int temp = b; b = a; a = temp%a; } if(b == 1) { return true; } else { return false; }
}
}