結果
| 問題 |
No.573 a^2[i] = a[i]
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-05-10 03:48:34 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,164 bytes |
| コンパイル時間 | 13,088 ms |
| コンパイル使用メモリ | 434,448 KB |
| 実行使用メモリ | 62,028 KB |
| 最終ジャッジ日時 | 2024-12-18 00:50:24 |
| 合計ジャッジ時間 | 30,097 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 27 |
ソースコード
import kotlin.math.pow
fun main() {
val mod = 1_000_000_007L
val n = readLine()!!.toInt()
val fact = LongArray(2 * 10.0.pow(5).toInt() + 1) { 1L }
for (i in 1 until fact.size) {
fact[i] = fact[i - 1] * i % mod
}
val factInv = LongArray(fact.size) { i ->
if (i == fact.lastIndex) fact.last().modPow(mod - 2, mod)
else 0L
}
for (i in fact.lastIndex - 1 downTo 0) {
factInv[i] = factInv[i + 1] * (i + 1) % mod
}
fun combi(a: Int, b: Int): Long {
return if (0 <= b && b <= a) {
fact[a] * factInv[b] % mod * factInv[a - b] % mod
} else {
0L
}
}
var ans = 0L
for (i in 1..n) {
ans = (ans + combi(n, i) * i.toDouble().pow((n - i).toDouble()).toLong() % mod) % mod
}
println(ans)
}
private fun Long.modPow(exponent: Long, modulus: Long): Long {
var result = 1L
var exp = exponent
var base = this % modulus
while (exp > 0) {
if (exp and 1 == 1L) {
result = (result * base) % modulus
}
base = (base * base) % modulus
exp = exp shr 1
}
return result
}
titia