結果

問題 No.648  お や す み 
コンテスト
ユーザー keiden
提出日時 2024-09-20 21:04:24
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 420 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,679 ms
コンパイル使用メモリ 257,524 KB
実行使用メモリ 54,956 KB
最終ジャッジ日時 2026-03-09 20:16:02
合計ジャッジ時間 38,712 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import scala.io.StdIn.readLong
import scala.math._

def sqrtLong(n: Long): Long =
    if (n == 0 || n == 1) return n
    var x0 = n / 2
    var x1 = (x0 + n / x0) / 2
    while (x1 < x0)
        x0 = x1
        x1 = (x0 + n / x0) / 2
    x0

@main
def yuki648(): Unit =
    val n = 2 * readLong
    val k = sqrtLong(n)
    if n == k * (k + 1) then
        println("YES")
        println(k)
    else
        println("NO")
0