結果

問題 No.884 Eat and Add
ユーザー hirogahiroga
提出日時 2019-12-30 11:19:56
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,013 bytes
コンパイル時間 14,326 ms
コンパイル使用メモリ 415,936 KB
実行使用メモリ 59,796 KB
最終ジャッジ日時 2023-08-07 18:15:54
合計ジャッジ時間 25,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 319 ms
53,756 KB
testcase_01 AC 315 ms
53,616 KB
testcase_02 AC 318 ms
53,456 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 537 ms
56,332 KB
testcase_08 AC 540 ms
56,296 KB
testcase_09 TLE -
testcase_10 AC 321 ms
53,500 KB
testcase_11 AC 313 ms
53,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://yukicoder.me/problems/no/884

package yukicoder

import java.math.BigInteger
import java.util.*

fun main() {
    val num = Scanner(System.`in`).nextBigInteger(2)
    println(no884(num))
}

fun no884(num: BigInteger): Int {
    return get2の累乗との差が0になるまで2の累乗を足すか引くかし続けた回数(num)
}

fun get2の累乗との差が0になるまで2の累乗を足すか引くかし続けた回数(num: BigInteger): Int {
    var 最寄りの2の累乗との差 = get最寄りの2の累乗との差(num)
    var count = 1

    while (最寄りの2の累乗との差 != BigInteger.valueOf(0)) {
        最寄りの2の累乗との差 = get最寄りの2の累乗との差(最寄りの2の累乗との差)
        count += 1
    }
    return count
}

fun get最寄りの2の累乗との差(num: BigInteger): BigInteger {
    val digit = num.bitLength()
    return num.minus(BigInteger("1").shiftLeft(digit - 1)).min(
        BigInteger("1").shiftLeft(digit) - num
    )
}

0