結果

問題 No.1593 Perfect Distance
ユーザー merlinmerlin
提出日時 2021-07-09 21:27:41
言語 Java19
(openjdk 21)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 72,200 KB
実行使用メモリ 50,920 KB
最終ジャッジ日時 2023-09-14 07:45:32
合計ジャッジ時間 3,965 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,044 KB
testcase_01 AC 44 ms
49,140 KB
testcase_02 AC 44 ms
49,180 KB
testcase_03 AC 42 ms
49,052 KB
testcase_04 AC 47 ms
49,076 KB
testcase_05 AC 43 ms
49,084 KB
testcase_06 AC 43 ms
49,156 KB
testcase_07 AC 42 ms
49,168 KB
testcase_08 AC 43 ms
49,392 KB
testcase_09 AC 51 ms
49,456 KB
testcase_10 AC 53 ms
49,676 KB
testcase_11 AC 56 ms
50,768 KB
testcase_12 AC 62 ms
50,624 KB
testcase_13 AC 62 ms
50,680 KB
testcase_14 AC 63 ms
50,920 KB
testcase_15 AC 68 ms
50,744 KB
testcase_16 AC 72 ms
50,664 KB
testcase_17 AC 42 ms
49,164 KB
testcase_18 AC 42 ms
49,164 KB
testcase_19 AC 43 ms
49,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        long sq=1l*n*n; int i,ans=0;
        for(i=1;i<n;i++)
        {
            long dif=sq-1l*i*i;
            long rt=root(dif);
            rt*=rt;
            if(rt==dif) ans++;
        }
        System.out.print(ans);
    }

    static int root(long n)
    {
        int l=1,r=(int)1e9,mid,ans=r;
        while(l<=r)
        {
            mid=(l+r)>>1;
            if(1l*mid*mid>=n)
            {
                r=mid-1;
                ans=mid;
            }
            else l=mid+1;
        }
        return ans;
    }
}
0