結果

問題 No.1593 Perfect Distance
ユーザー lavoxlavox
提出日時 2021-07-09 21:35:37
言語 Java
(openjdk 23)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 74,760 KB
実行使用メモリ 41,376 KB
最終ジャッジ日時 2024-07-01 15:23:45
合計ジャッジ時間 5,552 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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