米勒羅賓素數測試版-哥德巴赫猜想
阿新 • • 發佈:2018-12-12
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <time.h> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <stdlib.h> typedef long long ll; typedef unsigned long long LL; # define PI acos(-1.0) # define mst(a,b) memset(a,b,sizeof(a)) # define IOS ios::sync_with_stdio(false); const int INF = 0x3f3f3f3f; const double eps = 1e-7; const ll mod = 1e9+7; # define N 7 # define Times 11 using namespace std; int prime[100010]; // 存素數 bool vis[100010]; int cnt = 0; void doprime(int n){ mst(vis, 0); mst(prime, 0); for(int i = 2; i <= n; i++){ if(!vis[i]){ prime[cnt++] = i; } for(int j = 0; j <cnt && i *prime[j] <= n; j++){ vis[i * prime[j]] = true; if(i % prime[j] == 0){ break; } } } } LL random(LL n) { return (LL)((double)rand()/RAND_MAX*n+0.5); } LL multi(LL a, LL b, LL m)// a*b%m { LL ret = 0; while(b > 0) { if(b&1) ret = (ret + a) % m; b >>= 1; a = (a << 1) % m; } return ret; } LL quick_mod(LL a, LL b, LL m) { LL ans = 1; while(b) { if(b&1) { ans = multi(ans,a,m); b--; } b /= 2; a = multi(a, a, m); } return ans; } bool Witness(LL a, LL n) { LL m = n - 1; int j = 0; while(!(m&1)) { j++; m>>=1; } LL x = quick_mod(a, m, n); if(x==1||x==n-1) return false; while(j--) { x = x * x % n; if(x == n - 1) return false; } return true; } bool miller_rabin(LL n) { //cout<<n<<endl; /*for(LL i=1;i<=N;i++) { LL a=random(n-2)+1; if(quick_mod(a,n-1,n)!=1) return false; } return true; */ if(n < 2) return false; if(n == 2) return true; if(!(n&1)) return false; for(LL i = 1;i <= Times; i++) { LL a = random(n - 2) + 1; if(Witness(a, n)) return false; } return true; } int main(int argc, char * argv[]) { doprime(100000); int t; scanf("%d", &t); while(t--){ LL x; scanf("%llu", &x); for(int i = 1; i < 100000; i++){ if(miller_rabin(i) && miller_rabin(x-i)){ printf("%d %llu\n", i,x-i); bareak; } } } return 0; }