結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー surumeika1987surumeika1987
提出日時 2020-11-19 17:33:13
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,015 bytes
コンパイル時間 12,806 ms
コンパイル使用メモリ 439,908 KB
実行使用メモリ 90,632 KB
最終ジャッジ日時 2024-04-29 14:34:45
合計ジャッジ時間 21,098 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 296 ms
49,800 KB
testcase_01 AC 293 ms
49,544 KB
testcase_02 AC 313 ms
49,944 KB
testcase_03 AC 327 ms
49,912 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger

fun main() {
    val n_num = readLine()!!.toInt()
    repeat(n_num) {
        val bg = readLine()!!.toBigInteger()
        val isp = IsPrime.Miller_Rabin.isPrime(bg)
        println(if (isp) "${bg} 1" else "${bg} 0")
    }
}

class IsPrime {
    companion object Miller_Rabin {
        fun isPrime(num: BigInteger) : Boolean{
            if (1.toBigInteger() == num) return false
            if (2.toBigInteger() == num) return true
            if (num.mod(2.toBigInteger()) == BigInteger.ZERO) return false
            var s = 0
            var t = num - 1.toBigInteger()
            while (t.and(1.toBigInteger()) == BigInteger.ZERO) {
                s = s + 1
                t = t.shr(1)
            }
            val a = 3.toBigInteger()
            if (a.modPow(t, num) == 1.toBigInteger()) return true
            for (i in 0..s-1)
                if (a.modPow(2.toBigInteger().pow(i), num) == num.minus(1.toBigInteger())) return true

            return false
        }
    }
}
0