結果

問題 No.648  お や す み 
コンテスト
ユーザー vjudge1
提出日時 2025-11-24 16:49:58
言語 Crystal
(1.14.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 14,485 ms
コンパイル使用メモリ 313,920 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-24 16:50:16
合計ジャッジ時間 14,849 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

require "big"
lib C
    fun getchar_unlocked : Int32
end
def read_i : Int64
    ans = 0_i64
    f = 1
    c = C.getchar_unlocked()
    while [9, 10, 11, 12, 13, 32].includes?(c)
        c = C.getchar_unlocked()
    end
    if c == 45
        f = -1
        c = C.getchar_unlocked()
    end
    while (48 .. 57).includes?(c)
        ans = (ans << 1_i64) + (ans << 3_i64) + (c ^ 48).to_i64
        c = C.getchar_unlocked()
    end
    return ans * f.to_i64
end
def work(n : Int64)
    l = 0_i64
    r = 3001001001_i64
    while l + 1_i64 < r
        m = (l + r) >> 1_i64
        if m * (m + 1_i64) >> 1_i64 > n
            r = m
        else
            l = m
        end
    end
    if l * (l + 1_i64) >> 1_i64 == n
        puts("YES")
        puts(l)
    else
        puts("NO")
    end
end
work(read_i)
0