結果
問題 | No.152 貯金箱の消失 |
ユーザー |
![]() |
提出日時 | 2020-06-10 15:46:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 468 ms / 5,000 ms |
コード長 | 1,921 bytes |
コンパイル時間 | 3,465 ms |
コンパイル使用メモリ | 87,252 KB |
実行使用メモリ | 76,808 KB |
最終ジャッジ日時 | 2024-06-23 06:46:26 |
合計ジャッジ時間 | 7,422 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
import java.util.*;public class Main {public static void main (String[] args) {Scanner sc = new Scanner(System.in);int length = sc.nextInt();boolean flag = true;long tate = 1;HashSet<Triangle> set = new HashSet<>();while (flag) {long yoko = tate + 1;while (flag) {Triangle t = new Triangle(tate, yoko);if (t.length() > length) {if (yoko == tate + 1) {flag = false;}break;} else {if (t.isOrg()) {set.add(t);}}yoko++;}tate++;}System.out.println(set.size());}static class Triangle {long[] abc = new long[3];public Triangle(long tate, long yoko) {abc[0] = yoko * yoko - tate * tate;abc[1] = yoko * tate * 2;abc[2] = yoko * yoko + tate * tate;Arrays.sort(abc);}public boolean isOrg() {return getGCD(abc) == 1;}public boolean equals(Object o) {Triangle t = (Triangle)o;for (int i = 0; i < 3; i++) {if (abc[i] != t.abc[i]) {return false;}}return true;}public long length() {long ans = 0;for (int i = 0; i < 3; i++) {ans += abc[i];}return ans * 4;}public int hashCode() {return (int)abc[0];}public String toString() {return abc[0] + ":" + abc[1] + ":" + abc[2];}}static long getGCD(long x, long y) {if (x % y == 0) {return y;} else {return getGCD(y, x % y);}}static long getGCD(long[] arr) {long ans = arr[0];for (int i = 1; i < arr.length; i++) {ans = getGCD(ans, arr[i]);}return ans;}}