結果

問題 No.1593 Perfect Distance
ユーザー lavoxlavox
提出日時 2021-07-09 21:35:37
言語 Java19
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 72,636 KB
実行使用メモリ 55,868 KB
最終ジャッジ日時 2023-09-14 07:57:46
合計ジャッジ時間 5,765 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,868 KB
testcase_01 AC 120 ms
55,584 KB
testcase_02 AC 119 ms
55,484 KB
testcase_03 AC 119 ms
55,704 KB
testcase_04 AC 118 ms
55,732 KB
testcase_05 AC 118 ms
55,348 KB
testcase_06 AC 118 ms
55,476 KB
testcase_07 AC 118 ms
55,612 KB
testcase_08 AC 119 ms
55,576 KB
testcase_09 AC 119 ms
55,764 KB
testcase_10 AC 120 ms
55,600 KB
testcase_11 AC 124 ms
55,656 KB
testcase_12 AC 129 ms
55,620 KB
testcase_13 AC 129 ms
55,620 KB
testcase_14 AC 129 ms
55,748 KB
testcase_15 AC 131 ms
55,664 KB
testcase_16 AC 132 ms
55,484 KB
testcase_17 AC 119 ms
55,820 KB
testcase_18 AC 120 ms
55,504 KB
testcase_19 AC 119 ms
55,812 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