結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー 👑 箱星箱星
提出日時 2020-10-09 23:22:58
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,205 bytes
コンパイル時間 13,444 ms
コンパイル使用メモリ 418,484 KB
実行使用メモリ 50,436 KB
最終ジャッジ日時 2023-09-27 19:47:00
合計ジャッジ時間 20,564 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 259 ms
50,432 KB
testcase_01 AC 260 ms
49,928 KB
testcase_02 AC 250 ms
50,436 KB
testcase_03 AC 253 ms
49,792 KB
testcase_04 AC 258 ms
49,952 KB
testcase_05 AC 264 ms
50,060 KB
testcase_06 AC 268 ms
50,064 KB
testcase_07 AC 269 ms
49,896 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

import java.math.BigInteger

fun PrintWriter.solve(sc: FastScanner) {
    val t = sc.nextInt()
    for (_i in 0 until t) {
        val n = sc.nextInt()
        println(f(n - 1))
    }
}

fun f(n: Int): Int {
    var s = 0
    var m = 1
    var N = 2 * n + 1
    while (true) {
        val k = N + m
        var x = k
        var v = 0
        while (x % 2 == 0) {
            x /= 2
            v++
        }
        s += v
        m = k shr v
        if (m == 1) break
    }
    return s
}

fun main() {
    val writer = PrintWriter(System.out, !false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}
0