結果

問題 No.152 貯金箱の消失
ユーザー ぴろずぴろず
提出日時 2015-02-15 23:32:33
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,360 bytes
コンパイル時間 3,512 ms
コンパイル使用メモリ 77,396 KB
実行使用メモリ 63,520 KB
最終ジャッジ日時 2023-09-06 01:21:38
合計ジャッジ時間 17,292 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,868 KB
testcase_01 AC 152 ms
55,820 KB
testcase_02 AC 126 ms
55,788 KB
testcase_03 AC 144 ms
55,664 KB
testcase_04 AC 2,779 ms
58,128 KB
testcase_05 AC 3,246 ms
56,228 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package no152;

import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt() / 4;
		HashSet<Pair<Integer,Integer>> hs = new HashSet<>();
		for(long a=1;a<=l/2;a++) {
			for(long b=a;a+b<l;b++) {
				long cSquare = a * a + b * b;
				long c = (long) Math.sqrt(cSquare + 0.5);
				if (c * c != cSquare || a + b + c > l) {
					continue;
				}
				long gcd = gcd(a,b);
				hs.add(new Pair<>((int) (a/gcd),(int) (b/gcd)));
			}
		}
//		System.out.println(hs);
		System.out.println(hs.size() % 1000003);
	}
	public static long gcd(long a,long b) {
		while(b!=0) {
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}


}
class Pair<A extends Comparable<A>,B extends Comparable<B>> implements Comparable<Pair<A,B>>{
	A a;
	B b;
	public Pair(A a,B b) {
		this.a = a;
		this.b = b;
	}
	public int compareTo(Pair<A, B> o) {
		int comp = a.compareTo(o.a);
		if (comp != 0) {
			return comp;
		}
		return b.compareTo(o.b);
	}
	public boolean equals(Object o) {
		if (o instanceof Pair) {
			@SuppressWarnings("rawtypes")
			Pair p = (Pair) o;
			return a.equals(p.a) && b.equals(p.b);
		}
		return super.equals(o);
	}
	public int hashCode() {
		return a.hashCode() + b.hashCode();
	}
	public String toString() {
		return "[" + a + "," + b + "]";
	}
}
0