結果
問題 | No.152 貯金箱の消失 |
ユーザー |
![]() |
提出日時 | 2015-02-16 00:15:18 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 155 ms / 5,000 ms |
コード長 | 1,193 bytes |
コンパイル時間 | 2,372 ms |
コンパイル使用メモリ | 79,340 KB |
実行使用メモリ | 41,612 KB |
最終ジャッジ日時 | 2024-06-23 20:35:27 |
合計ジャッジ時間 | 4,532 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
package no152; import java.util.Scanner; // http://ja.wikipedia.org/wiki/%E3%83%94%E3%82%BF%E3%82%B4%E3%83%A9%E3%82%B9%E3%81%AE%E5%AE%9A%E7%90%86 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int l = sc.nextInt() / 4; int ans = 0; for(long n=1;n<=l;n++) { for(long m=n+1;2*m*(n+m)<=l;m+=2) { if (gcd(n,m) == 1) { ans++; } } } System.out.println(ans % 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 + "]"; } }