結果

問題 No.276 連続する整数の和(1)
ユーザー rutilicusrutilicus
提出日時 2020-12-16 23:33:52
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 301 ms / 1,000 ms
コード長 362 bytes
コンパイル時間 14,955 ms
コンパイル使用メモリ 427,260 KB
実行使用メモリ 54,220 KB
最終ジャッジ日時 2023-10-20 09:58:27
合計ジャッジ時間 16,386 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
54,212 KB
testcase_01 AC 292 ms
54,216 KB
testcase_02 AC 296 ms
54,220 KB
testcase_03 AC 296 ms
54,220 KB
testcase_04 AC 291 ms
54,216 KB
testcase_05 AC 294 ms
54,212 KB
testcase_06 AC 295 ms
54,204 KB
testcase_07 AC 297 ms
54,216 KB
testcase_08 AC 296 ms
54,212 KB
testcase_09 AC 301 ms
54,212 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