結果

問題 No.8030 ミラー・ラビン素数判定法のテスト
ユーザー iwkjosec
提出日時 2019-05-13 03:59:22
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,140 bytes
コンパイル時間 2,675 ms
コンパイル使用メモリ 109,864 KB
実行使用メモリ 30,240 KB
最終ジャッジ日時 2024-11-18 16:40:13
合計ジャッジ時間 6,284 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
プレゼンテーションモードにする

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class Program
{
static void Main()
{
var n = long.Parse(ReadLine());
for (int i = 0; i < n; i++)
{
var x = long.Parse(ReadLine());
WriteLine(x.ToString() + " " + (MillerRabin(x) ? "1" : "0"));
}
}
static bool MillerRabin(long n)
{
if (n < 2) return false;
if (n % 2 == 0) return n == 2;
var d = n - 1;
var s = 0;
while (d % 2 == 0)
{
s++;
d >>= 1;
}
var l = new int[] { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 };
for (int i = 0; i < l.Length && l[i] < n; i++)
{
var a = l[i];
var c = true;
var x = System.Numerics.BigInteger.ModPow(a, d, n);
if (x == 1) c = false;
for (int r = 0; r < s; r++)
{
if (x == n - 1) c = false;
x = x * x % n;
}
if (c) return false;
}
return true;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0