From d24ab714b958b9fece4631076e240739ad0dd23f Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 3 Oct 2016 22:15:25 +0200 Subject: Progress --- numalgo.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'numalgo.cpp') diff --git a/numalgo.cpp b/numalgo.cpp index 1db0763..f2ebac5 100644 --- a/numalgo.cpp +++ b/numalgo.cpp @@ -1,3 +1,4 @@ +#include #include #include "numalgo.h" @@ -31,7 +32,7 @@ Bigint egcd(const Bigint &a,const Bigint &b,Bigint &x,Bigint &y){ Bigint expmod(const Bigint &b,const Bigint &e,const Bigint &m){ assert(e>=0); assert(m>=1); - if(m==1)return Bigint(0); + if(m==1)return Bigint::zero; Bigint res(1); vector bits(e.bits()); for(int i=bits.size()-1;i>=0;i--){ @@ -42,9 +43,67 @@ Bigint expmod(const Bigint &b,const Bigint &e,const Bigint &m){ return res; } +Bigint isqrt(const Bigint &n){ + assert(n>=0); + if(n<=1)return n; + const int maxiter=20; //empirically, this should happen around 3.5 million bits in n. (niter ~= -1.87+1.45ln(bits)) + // __asm("int3\n\t"); + // cout<<"bitcount="<