結果
問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
ユーザー |
![]() |
提出日時 | 2018-02-09 10:45:19 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 370 ms / 9,973 ms |
コード長 | 895 bytes |
コンパイル時間 | 429 ms |
コンパイル使用メモリ | 21,760 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-16 23:06:42 |
合計ジャッジ時間 | 2,006 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.c: In function ‘run’: main.c:45:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d",&n); | ^~~~~~~~~~~~~~ main.c:48:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%lld",&x); | ^~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h> typedef long long int int64; int64 modPow(int64 r,int64 n,int64 mod){ int64 res=1; int64 t=r; while(n>0){ if(n&0x01) res=(int64)((__int128)res*t%mod); t=(int64)((__int128)t*t%mod); n>>=1; } return res; } int isPrime(const int64 n){ if(n<=1) return 0; if(n<=3) return 1; if(n%2==0) return 0; int64 d=n-1; int r=0; while(d%2==0){ d/=2; r++; } const int aa[]={2,3,5,7,11,13,17,19,23,29,31,37}; int i; for(i=0;i<12 && aa[i]<=n-2;i++){ int64 a=aa[i]; int64 x=modPow(a,d,n); if(x==1) continue; int k; for(k=0;k<r;k++){ if(x==n-1) break; x=(int64)((__int128)x*x%n); } if(k==r) return 0; } return 1; } void run(void){ int n; scanf("%d",&n); while(n>0){ int64 x; scanf("%lld",&x); printf("%lld %d\n",x,isPrime(x)); n--; } } int main(void){ run(); return 0; }