|
@@ -288,12 +288,13 @@ struct BigInt{
|
|
if(c < 0)return bitshiftRight(-c);
|
|
if(c < 0)return bitshiftRight(-c);
|
|
unsigned int sh = c % 64;
|
|
unsigned int sh = c % 64;
|
|
unsigned int jmp = c / 64;
|
|
unsigned int jmp = c / 64;
|
|
- if((unsigned int)jmp >= size() * sizeof(uint64_t)){std::fill(begin(),end(),0);return *this;}
|
|
|
|
|
|
+ if((unsigned int)jmp >= size()){std::fill(begin(),end(),0);return *this;}
|
|
auto it1 = begin();
|
|
auto it1 = begin();
|
|
auto it2 = it1 + jmp;
|
|
auto it2 = it1 + jmp;
|
|
auto beforeEnd = end() - 1;
|
|
auto beforeEnd = end() - 1;
|
|
while(it2 != beforeEnd){
|
|
while(it2 != beforeEnd){
|
|
*it1 = (*it2 << sh);
|
|
*it1 = (*it2 << sh);
|
|
|
|
+ if(sh)
|
|
*it1 |= (*(it2 + 1) >> (64 - sh));
|
|
*it1 |= (*(it2 + 1) >> (64 - sh));
|
|
++it1;++it2;
|
|
++it1;++it2;
|
|
}
|
|
}
|
|
@@ -310,12 +311,13 @@ struct BigInt{
|
|
if(c < 0)return bitshiftLeft(-c);
|
|
if(c < 0)return bitshiftLeft(-c);
|
|
unsigned int sh = c % 64;
|
|
unsigned int sh = c % 64;
|
|
unsigned int jmp = c / 64;
|
|
unsigned int jmp = c / 64;
|
|
- if((unsigned int)jmp >= size() * sizeof(uint64_t)){std::fill(begin(),end(),0);return *this;}
|
|
|
|
|
|
+ if((unsigned int)jmp >= size()){std::fill(begin(),end(),0);return *this;}
|
|
auto it1 = rbegin();
|
|
auto it1 = rbegin();
|
|
auto it2 = it1 + jmp;
|
|
auto it2 = it1 + jmp;
|
|
auto beforeRend = rend() - 1;
|
|
auto beforeRend = rend() - 1;
|
|
while(it2 != beforeRend){
|
|
while(it2 != beforeRend){
|
|
*it1 = (*it2 >> sh);
|
|
*it1 = (*it2 >> sh);
|
|
|
|
+ if(sh)
|
|
*it1 |= (*(it2 + 1) << (64 - sh));
|
|
*it1 |= (*(it2 + 1) << (64 - sh));
|
|
++it1;++it2;
|
|
++it1;++it2;
|
|
}
|
|
}
|
|
@@ -327,7 +329,51 @@ struct BigInt{
|
|
}
|
|
}
|
|
return *this;
|
|
return *this;
|
|
}
|
|
}
|
|
|
|
+ BigInt operator<<(int c)const{
|
|
|
|
+ BigInt ret = *this;
|
|
|
|
+ ret.bitshiftLeft(c);
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ BigInt operator>>(int c)const{
|
|
|
|
+ BigInt ret = *this;
|
|
|
|
+ ret.bitshiftRight(c);
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigInt& operator<<=(int c){
|
|
|
|
+ return bitshiftLeft(c);
|
|
|
|
+ }
|
|
|
|
+ BigInt& operator>>=(int c){
|
|
|
|
+ return bitshiftRight(c);
|
|
|
|
+ }
|
|
|
|
+ int bitDifference(const BigInt& o){
|
|
|
|
+ int pos1(-1),pos2(-1);
|
|
|
|
+ auto it1 = begin();
|
|
|
|
+ auto it2 = o.begin();
|
|
|
|
+ while(it1 != end()){
|
|
|
|
+ if(*it1 == 0)
|
|
|
|
+ pos1 += 64;
|
|
|
|
+ else{
|
|
|
|
+ pos1 += __builtin_clzll(*it1);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ ++it1;
|
|
|
|
+ }
|
|
|
|
+ if(pos1 == -1)pos1 = size() * 64;
|
|
|
|
+ while(it2 != end()){
|
|
|
|
+ if(*it2 == 0)
|
|
|
|
+ pos2 += 64;
|
|
|
|
+ else{
|
|
|
|
+ pos2 += __builtin_clzll(*it2);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ ++it2;
|
|
|
|
+ }
|
|
|
|
+ if(pos1 == -1)pos1 = o.size() * 64;
|
|
|
|
+ int sizediff = ((signed int)size()) - ((signed int)o.size());
|
|
|
|
+ return pos2 - pos1 + sizediff * 64;
|
|
|
|
+ }
|
|
inline BigInt& chunkshiftLeft(int c){
|
|
inline BigInt& chunkshiftLeft(int c){
|
|
if(c < 0)return chunkshiftRight(-c);
|
|
if(c < 0)return chunkshiftRight(-c);
|
|
if((unsigned int)c >= size()){std::fill(begin(),end(),0);return *this;}
|
|
if((unsigned int)c >= size()){std::fill(begin(),end(),0);return *this;}
|
|
@@ -411,6 +457,9 @@ struct BigInt{
|
|
}
|
|
}
|
|
return *this;
|
|
return *this;
|
|
}
|
|
}
|
|
|
|
+ inline BigInt moda(){
|
|
|
|
+
|
|
|
|
+ }
|
|
inline BigInt mult(const BigInt& o)const{
|
|
inline BigInt mult(const BigInt& o)const{
|
|
BigInt result(size() + o.size() + 1,0);
|
|
BigInt result(size() + o.size() + 1,0);
|
|
BigInt temp(size() + o.size() + 1,0);
|
|
BigInt temp(size() + o.size() + 1,0);
|