結果
| 問題 |
No.152 貯金箱の消失
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-02-15 23:32:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,360 bytes |
| コンパイル時間 | 2,433 ms |
| コンパイル使用メモリ | 83,724 KB |
| 実行使用メモリ | 48,392 KB |
| 最終ジャッジ日時 | 2024-06-23 20:26:18 |
| 合計ジャッジ時間 | 15,831 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 TLE * 1 -- * 5 |
ソースコード
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 + "]";
}
}
ぴろず