結果

問題 No.152 貯金箱の消失
ユーザー kohaku_kohaku
提出日時 2016-12-04 07:16:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 166 ms / 5,000 ms
コード長 870 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 41,304 KB
最終ジャッジ日時 2024-11-27 19:38:39
合計ジャッジ時間 4,406 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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