結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 236 ms
49,936 KB
testcase_01 AC 241 ms
50,128 KB
testcase_02 AC 245 ms
49,984 KB
testcase_03 AC 244 ms
50,064 KB
testcase_04 AC 242 ms
49,928 KB
testcase_05 AC 267 ms
50,136 KB
testcase_06 AC 263 ms
50,116 KB
testcase_07 AC 262 ms
50,116 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 - 1L))
    }
}

fun f(n: Long): Long {
    var s = 0L
    var m = 1L
    var N = 2 * n + 1
    while (true) {
        val k = N + m
        var x = k
        var v = 0
        while (x % 2 == 0L) {
            x /= 2
            v++
        }
        s += v
        m = k shr v
        if (m == 1L) 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