Browse Source

Modulo buggy

mawinkle 6 years ago
parent
commit
21fcb3cf7c
2 changed files with 23 additions and 8 deletions
  1. 12 1
      BigInt64.hpp
  2. 11 7
      test.cpp

+ 12 - 1
BigInt64.hpp

@@ -42,7 +42,7 @@ struct BigInt{
 	std::deque<uint64_t> data;
 	int signum;
 	inline BigInt() : data(1,0),signum(1){}
-	inline BigInt(size_t _s, uint64_t fill) : data(_s,fill), signum(1){}
+	inline BigInt(size_t _s, uint64_t fill) : data(_s, fill), signum(1){}
 	inline BigInt(int a) :  data(1, std::abs(a)),signum(::signum(a)){}
 	inline BigInt(unsigned int a) : data(1, a),signum(1){}
 	inline BigInt(unsigned long long a) : data(1, a), signum(1){}
@@ -51,6 +51,17 @@ struct BigInt{
 	inline BigInt(std::initializer_list<uint64_t>&& l) : data(std::move(l)), signum(1){}
 	inline BigInt(const BigInt& o) : data(o.data), signum(o.signum){}
 	inline BigInt(BigInt&& o) : data(std::move(o.data)), signum(o.signum){}
+	inline BigInt(const std::string& o){
+		auto it = o.rbegin();
+		BigInt baseTen(1);
+		while(it != o.rend()){
+			BigInt l = baseTen.mult(BigInt(*it - '0'));
+			adda(l);
+			baseTen = baseTen.mult(BigInt(10));
+			++it;
+		}
+		
+	}
 	template<typename InputIterator>
 	inline BigInt(InputIterator begin, InputIterator end) : data(begin, end), signum(1){}
 	template<typename RNG>

+ 11 - 7
test.cpp

@@ -28,14 +28,18 @@ std::ostream& operator<< <char>(std::ostream& out, std::vector<char> o){
 }
 int main(){
 	xoshiro_256 gen(1);
-	BigInt a(gen,10);
-	BigInt b(gen,8);
-	BigInt mod(gen, 10);
-	std::cout << "a: " << a.toString() << "\n";
+	BigInt a(323);
+	BigInt b(343453423ull);
+	//BigInt mod(gen, 5);
+	BigInt mod("179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624227998859");
+	mod.suba(BigInt(234723947982312ull));
+	std::cout << "Mod " << mod.toString() << std::endl;
+	std::cout << mod.rawString() << std::endl;
+	std::cout << "(" << a.toString() << " ^ " << std::flush;
 	a = a.modPow(b,mod);
-	std::cout << "b: " << b.toString() << "\n";
-	std::cout << "mod: " << mod.toString() << "\n";
-	std::cout << "Result: " << a.toString() << "\n";
+	std::cout << "" << b.toString() << ")";
+	std::cout << " mod " << mod.toString() << "\n";
+	std::cout << " = " << a.toString() << "\n";
 }
 /*int mian(){
 	cppsocket sock("192.168.178.79", 80);