結果

問題 No.1593 Perfect Distance
ユーザー lavoxlavox
提出日時 2021-07-09 21:35:37
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 2,076 ms
使用メモリ 37,960 KB
最終ジャッジ日時 2023-02-01 22:21:05
合計ジャッジ時間 5,414 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 92 ms
37,212 KB
testcase_01 AC 94 ms
37,364 KB
testcase_02 AC 91 ms
37,264 KB
testcase_03 AC 97 ms
37,464 KB
testcase_04 AC 94 ms
37,392 KB
testcase_05 AC 92 ms
37,232 KB
testcase_06 AC 92 ms
37,188 KB
testcase_07 AC 90 ms
37,420 KB
testcase_08 AC 92 ms
37,388 KB
testcase_09 AC 94 ms
37,368 KB
testcase_10 AC 98 ms
37,728 KB
testcase_11 AC 99 ms
37,616 KB
testcase_12 AC 106 ms
37,672 KB
testcase_13 AC 109 ms
37,892 KB
testcase_14 AC 105 ms
37,904 KB
testcase_15 AC 109 ms
37,960 KB
testcase_16 AC 118 ms
37,676 KB
testcase_17 AC 91 ms
37,280 KB
testcase_18 AC 92 ms
37,356 KB
testcase_19 AC 91 ms
37,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = Long.parseLong(sc.next());
		sc.close();
		
		long N2 = N * N;
		
		long cnt = 0;
		for ( long x = 1 ; x < N ; x++ ) {
			long a = N2 - x * x;
			long b = Math.round(Math.sqrt(a));
			long y = -1;
			if ( b * b == a ) {
				y = b;
			} else if ( (b - 1) * (b - 1) == a ) {
				y = b - 1;
			} else if ( (b + 1) * (b + 1) == a ) {
				y = b + 1;
			}
			
			if ( y != -1 ) {
				cnt++;
				//System.out.println(x + "," + y);
			}
		}

		System.out.println(cnt);
	}
}
0