結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
|
| 提出日時 | 2018-04-09 00:58:35 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,667 bytes |
| コンパイル時間 | 1,555 ms |
| コンパイル使用メモリ | 33,024 KB |
| 実行使用メモリ | 8,868 KB |
| 最終ジャッジ日時 | 2024-11-18 16:18:44 |
| 合計ジャッジ時間 | 43,836 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 3 TLE * 3 |
ソースコード
module mdl
contains
function mul_mod(a,b,m)result(ret)
implicit none
integer(8),value::a,b,m
integer(8)::ret,tmp
a=mod(a,m)
b=mod(b,m)
ret=0
do while(b>1)
if(mod(b,2)==0)then
tmp=a
if(tmp>=m-a)tmp=tmp-m
a=mod(a+tmp,m)
b=b/2
else
if(ret>=m-a)ret=ret-m
ret=mod(ret+a,m)
b=b-1
end if
end do
if(ret>=m-a)ret=ret-m
ret=mod(ret+a,m)
end function
integer(8) function pow(a,n,p)
implicit none
integer(8),value::a,n,p
a=mod(a,p)
pow=1
do while(n>0)
if(mod(n,2)==1)pow=mul_mod(pow,a,p)
n=n/2
a=mul_mod(a,a,p)
end do
end function
logical function isPrime(a)
integer(8)::i,j,k,x,tmp
integer(8),value::a
logical::flag
isPrime=.true.
do i=12,min(a-1,100)
tmp=pow(i,a-1,a)
isPrime=isPrime.and.tmp==1
if(.not.isPrime)return
end do
if(a<10000)then
do i=2,a
if(i*i>=a)exit
isPrime=isPrime.and.mod(a,i)/=0
if(isPrime)return
end do
end if
end function
end module
program main
use mdl
implicit none
integer::n
integer(8)::i,j,k
integer(8),allocatable::x(:)
read*,n
allocate(x(n))
do i=1,n
read*,x(i)
if(isPrime(x(i)))then
print*,x(i),1
else
print*,x(i),0
end if
end do
end program