From 0b7499f8775e728c4a349933a95fe450c082a338 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 4 Oct 2016 23:14:56 +0200 Subject: Add (non-working yet) Lucas test --- bigint.cpp | 11 +++++---- main.cpp | 12 ++++++++++ numalgo.cpp | 7 ++++-- primes.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- primes.h | 2 +- 5 files changed, 94 insertions(+), 12 deletions(-) diff --git a/bigint.cpp b/bigint.cpp index 21c4ab2..9fdafe0 100644 --- a/bigint.cpp +++ b/bigint.cpp @@ -133,8 +133,9 @@ Bigint& Bigint::operator=(slongdigit_t v){ } Bigint& Bigint::operator+=(const Bigint &o){ - if(&o==this){ - return *this=Bigint(*this)+=o; + if(&o==this){ //*this + *this + operator<<=(1); + return *this; } if(sign==1){ if(o.sign==1)add(*this,o); @@ -148,8 +149,10 @@ Bigint& Bigint::operator+=(const Bigint &o){ } Bigint& Bigint::operator-=(const Bigint &o){ - if(&o==this){ - return *this=Bigint(*this)-=o; + if(&o==this){ // *this - *this + sign=1; + digits.clear(); + return *this; } if(sign==1){ if(o.sign==1)subtract(*this,o); diff --git a/main.cpp b/main.cpp index db846a9..43d2de7 100644 --- a/main.cpp +++ b/main.cpp @@ -153,6 +153,16 @@ void fermatpseudo(){ cout<=b)a=a.divmod(b).second; + if(a.compareAbs(b)==1)a=a.divmod(b).second; else b=b.divmod(a).second; } } @@ -45,13 +45,16 @@ Bigint expmod(const Bigint &b,const Bigint &e,const Bigint &m){ int jacobiSymbol(Bigint a,Bigint n){ //https://en.wikipedia.org/wiki/Jacobi_symbol#Calculating_the_Jacobi_symbol + // cerr<<"jacobiSymbol("<0&&n.odd()); int res=1; while(true){ + // cerr<<" a="<