結果

問題 No.1593 Perfect Distance
コンテスト
ユーザー Kenneth Yong
提出日時 2021-07-09 22:42:05
言語 Kotlin
(2.3.10)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 413 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,941 ms
コンパイル使用メモリ 426,016 KB
実行使用メモリ 56,324 KB
最終ジャッジ日時 2026-03-22 19:20:07
合計ジャッジ時間 12,251 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import kotlin.math.sqrt
import kotlin.math.round

fun main() {
	val n = readLine()!!.toLong();
	
	// a^2 + b^2 = n^2 -> 1 <= a < n
	var ans = 0;
	for (a in 1L..(n - 1)) {
		val current = n * n - a * a;
		val root = round(sqrt(current.toDouble())).toLong();
		if (current == (root * root)) ans++;
	}
	
	println(ans);
}
/*
C:\Users\kenne\OneDrive\Desktop\competitive_programming\kotlinmain.kt
*/
0