結果

問題 No.1161 Many Powers
ユーザー 👑 箱星箱星
提出日時 2020-08-19 18:04:36
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 1,364 bytes
コンパイル時間 12,512 ms
コンパイル使用メモリ 443,164 KB
実行使用メモリ 60,972 KB
最終ジャッジ日時 2024-04-20 09:41:20
合計ジャッジ時間 21,833 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
54,196 KB
testcase_01 AC 280 ms
54,304 KB
testcase_02 AC 284 ms
54,368 KB
testcase_03 AC 284 ms
54,360 KB
testcase_04 AC 281 ms
54,288 KB
testcase_05 AC 293 ms
54,472 KB
testcase_06 AC 292 ms
54,300 KB
testcase_07 AC 279 ms
54,396 KB
testcase_08 AC 337 ms
56,532 KB
testcase_09 AC 338 ms
56,580 KB
testcase_10 AC 307 ms
56,324 KB
testcase_11 AC 331 ms
56,516 KB
testcase_12 AC 307 ms
56,632 KB
testcase_13 AC 354 ms
58,596 KB
testcase_14 AC 402 ms
58,760 KB
testcase_15 AC 387 ms
58,948 KB
testcase_16 AC 412 ms
60,956 KB
testcase_17 AC 376 ms
58,820 KB
testcase_18 AC 340 ms
58,556 KB
testcase_19 AC 318 ms
56,560 KB
testcase_20 AC 416 ms
60,972 KB
testcase_21 AC 316 ms
56,568 KB
testcase_22 AC 418 ms
60,760 KB
testcase_23 AC 285 ms
54,372 KB
testcase_24 AC 280 ms
54,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve(sc: FastScanner) {
    val a = sc.nextLong()
    val b = sc.nextLong()
    val c = sc.nextInt()
    val arr = Array(c) { 0L }
    for (i in 1 until c) {
        arr[i] = modpow(i.toLong(), b, c)
    }
    val sum = Array(c + 1) { 0L }
    for (i in 0 until c) {
        sum[i + 1] = sum[i] + arr[i]
    }
    var ans = sum[c] * (a / c) % c + sum[((a + 1) % c).toInt()]
    ans %= c
    println(ans)
}

fun modpow(a:Long, b:Long, c:Int): Long {
    if (b == 0L) return if (a % c == 0L) 0 else 1
    if (b == 1L) return a % c
    val p = modpow(a, b / 2, c)
    val pp = p * p % c
    return if (b % 2 == 0L) pp else pp * a % c
}

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