2018宁夏网络赛 B Goldbach(miller-rabin素数测试(含卡迈尔克数))

题目:https://nanti.jisuanke.com/t/25985

题意:

让你求出符合哥德巴赫猜想的任意两个加数。

思路:

数太大,用miller-rabin素数测试。

2018宁夏网络赛 B Goldbach(miller-rabin素数测试(含卡迈尔克数))_第1张图片2018宁夏网络赛 B Goldbach(miller-rabin素数测试(含卡迈尔克数))_第2张图片2018宁夏网络赛 B Goldbach(miller-rabin素数测试(含卡迈尔克数))_第3张图片

#include
#define ll unsigned long long int
using namespace std;

ll ModMul(ll a,ll b,ll n){//快速积取模 a*b%n
    ll ans=0;
    while(b){
        if(b&1)
        ans=(ans+a)%n;
        a=(a+a)%n;
        b>>=1;
    }
    return ans;
}
ll ModExp(ll a,ll b,ll n){  //快速幂取模 a^b%n
    ll ans=1;
    while(b){
        if(b&1)
        ans=ModMul(ans,a,n);
        a=ModMul(a,a,n);
        b>>=1;
    }
    return ans;
}
bool miller_rabin(ll n){//Miller-Rabin素数检测算法
    ll i,j,a,x,y,t,u,s=10;
    if(n==2)
        return true;
    if(n<2||!(n&1))
        return false;
    for(t=0,u=n-1;!(u&1);t++,u>>=1); //n-1=u*2^t
    for(i=0;i>t;
    while(t--){
        scanf("%lld",&n);
        if(n==4)
            cout<<2<<" "<<2<

你可能感兴趣的:(gcd,同余问题)