結果

問題 No.276 連続する整数の和(1)
ユーザー rutilicusrutilicus
提出日時 2020-12-16 23:33:52
言語 Kotlin
(1.8.10)
結果
AC  
実行時間 304 ms / 1,000 ms
コード長 362 bytes
コンパイル時間 12,832 ms
コンパイル使用メモリ 412,496 KB
実行使用メモリ 53,052 KB
最終ジャッジ日時 2023-07-20 08:40:18
合計ジャッジ時間 17,353 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 301 ms
52,896 KB
testcase_01 AC 299 ms
52,628 KB
testcase_02 AC 303 ms
52,816 KB
testcase_03 AC 300 ms
52,660 KB
testcase_04 AC 299 ms
52,604 KB
testcase_05 AC 299 ms
52,544 KB
testcase_06 AC 301 ms
52,920 KB
testcase_07 AC 302 ms
53,052 KB
testcase_08 AC 304 ms
52,952 KB
testcase_09 AC 303 ms
52,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:6:13: warning: 'appendln(Long): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln(gcd(n, n * (n + 1L) / 2L))
            ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toLong()

    builder.appendln(gcd(n, n * (n + 1L) / 2L))

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}

tailrec fun gcd(a: Long, b: Long): Long =
    when {
        b > a -> gcd(b, a)
        b == 0L -> a
        else -> gcd(b, a % b)
    }
0