結果

問題 No.152 貯金箱の消失
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-04 07:16:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 163 ms / 5,000 ms
コード長 870 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 71,164 KB
実行使用メモリ 55,920 KB
最終ジャッジ日時 2023-08-18 14:04:16
合計ジャッジ時間 4,675 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,700 KB
testcase_01 AC 127 ms
55,920 KB
testcase_02 AC 127 ms
55,828 KB
testcase_03 AC 125 ms
55,636 KB
testcase_04 AC 127 ms
55,784 KB
testcase_05 AC 128 ms
55,648 KB
testcase_06 AC 127 ms
55,680 KB
testcase_07 AC 136 ms
55,468 KB
testcase_08 AC 162 ms
55,808 KB
testcase_09 AC 163 ms
55,496 KB
testcase_10 AC 157 ms
55,712 KB
testcase_11 AC 150 ms
55,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num=0;
        int L = sc.nextInt();
        L/=4;
        int rt = (int)Math.sqrt(L/2);
        for(int m=2; m<=rt; m++){
            for(int n=1; n<m; n++){
                if((m-n)%2==1){
                    int t =gcd(m,n);
                    if(t==1){
                        int a=m*m-n*n;
                        int b=2*m*n;
                        int c=m*m+n*n;
                        if( (a+b+c)<=L){
                            num++;
                        }
                    }
                }
            }
        }
        System.out.println(num);
    }
    static int gcd(int a, int b){
        while(a%b!=0){
            int t=b;
            b=a%b;
            a=t;
        }
        return b;
    }
}
0