diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-10-08 13:46:59 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-10-08 13:52:05 +0200 |
commit | 00c059d4554f70fc52d94ff1d5dd28976bf857fb (patch) | |
tree | 40d5ddc83133892a87503b370bebf2cb9990ebef /primes.cpp | |
parent | 264fb4b2bb5480a28646a8465013647b2e034cf4 (diff) |
Code cleanup
Diffstat (limited to 'primes.cpp')
-rw-r--r-- | primes.cpp | 22 |
1 files changed, 1 insertions, 21 deletions
@@ -11,7 +11,6 @@ vector<int> smallprimes; bool smallprimes_inited=false; void fillsmallprimes(){ - // cerr<<"Filling small primes..."<<endl; smallprimes_inited=true; //TODO: reserve expected amount of space in smallprimes smallprimes.push_back(2); @@ -27,8 +26,6 @@ void fillsmallprimes(){ composite[j/2-1]=true; } } - //for(int p : smallprimes)cerr<<p<<' '; - //cerr<<endl; } pair<Bigint,Bigint> genprimepair(Rng &rng,int nbits){ @@ -56,15 +53,12 @@ Bigint randprime(Rng &rng,const Bigint &biglow,const Bigint &bighigh){ if(diff<=maxrangesize){ low=biglow; high=bighigh; - // cerr<<"low=biglow="<<low<<" high=bighigh="<<high<<endl; } else { high=low=bigrandom(rng,diff-maxrangesize); high+=maxrangesize; - // cerr<<"low="<<low<<" high="<<high<<endl; } if(low.even())low+=1; if(high.even())high-=1; - // cerr<<"low="<<low<<" high="<<high<<endl; Bigint sizeb(high-low+1); assert(sizeb>=0&&sizeb<=maxrangesize); int nnums=(sizeb.lowdigits()+1)/2; @@ -83,23 +77,18 @@ Bigint randprime(Rng &rng,const Bigint &biglow,const Bigint &bighigh){ if(lowoffset==0)startat=0; else if((pr-lowoffset)%2==0)startat=(pr-lowoffset)/2; else startat=(pr-lowoffset+pr)/2; - // cerr<<"pr="<<pr<<" lowoffset="<<lowoffset<<" startat="<<startat<<endl; for(int i=startat;i<nnums;i+=pr){ //skips ahead `2*pr` each time (so `pr` array elements) - // cerr<<"sieving composite["<<i<<"]: "<<low+2*i<<endl; nleft-=!composite[i]; composite[i]=true; } } vector<int> maybeprimes; maybeprimes.reserve(nleft); - // cerr<<"Left ("<<nleft<<"):"; for(int i=0;i<nnums;i++){ if(!composite[i]){ - // cerr<<' '<<low+2*i; maybeprimes.push_back(i); } } - // cerr<<endl; while(maybeprimes.size()){ int idx=rng.get_uniform(maybeprimes.size()); @@ -148,13 +137,10 @@ bool strongLucasPrime(const Bigint &n){ } } //now we have a D - // cerr<<"D="<<D<<endl; int P=1,iQ=(1-D)/4; if(gcd(n,Bigint(P)).compareAbs(1)!=0||gcd(n,Bigint(iQ)).compareAbs(1)!=0)return false; //would be too easy to ignore - // cerr<<"ok"<<endl; //now begin the actual sequence algorithm -#if 1 int s=0; Bigint d(n); d+=1; @@ -162,11 +148,7 @@ bool strongLucasPrime(const Bigint &n){ d>>=1; s++; } -#else - Bigint d(n); - d+=1; -#endif - // cerr<<"d="<<d<<endl; + vector<bool> dbits=d.bits(); assert(dbits.size()>0); assert(dbits[dbits.size()-1]==true); @@ -198,7 +180,6 @@ bool strongLucasPrime(const Bigint &n){ } } if(U==0)return true; -#if 1 if(V==0)return true; //r=0 check for(int r=1;r<s;r++){ V*=V; @@ -207,7 +188,6 @@ bool strongLucasPrime(const Bigint &n){ Qk=(Qk*Qk).divmod(n).second; if(V==0)return true; } -#endif return false; } |