upd: ready to optimize /
This commit is contained in:
@ -555,7 +555,7 @@ inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
|
|||||||
int2048 x_pre(x);
|
int2048 x_pre(x);
|
||||||
int2048 kOne(1);
|
int2048 kOne(1);
|
||||||
UnsignedMinus(x_pre, &kOne);
|
UnsignedMinus(x_pre, &kOne);
|
||||||
int cnt = 0;
|
// int cnt = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
/**
|
/**
|
||||||
* x_{n+1}=2*x_n-x_n*x_n*B/(10^L1))
|
* x_{n+1}=2*x_n-x_n*x_n*B/(10^L1))
|
||||||
@ -563,6 +563,8 @@ inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
|
|||||||
int2048 tmp = *pB;
|
int2048 tmp = *pB;
|
||||||
UnsignedMultiply(tmp, &x);
|
UnsignedMultiply(tmp, &x);
|
||||||
UnsignedMultiply(tmp, &x);
|
UnsignedMultiply(tmp, &x);
|
||||||
|
// std::cerr << "max length ratio during computing"
|
||||||
|
// << (double)tmp.num_length / (double)L1 << std::endl;
|
||||||
tmp.RightMoveBy(L1);
|
tmp.RightMoveBy(L1);
|
||||||
int2048 x_next = x;
|
int2048 x_next = x;
|
||||||
UnsignedAdd(x_next, &x);
|
UnsignedAdd(x_next, &x);
|
||||||
@ -571,7 +573,9 @@ inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
|
|||||||
if (UnsignedCmp(x_next, x_pre) == 0) break;
|
if (UnsignedCmp(x_next, x_pre) == 0) break;
|
||||||
x_pre = std::move(x);
|
x_pre = std::move(x);
|
||||||
x = std::move(x_next);
|
x = std::move(x_next);
|
||||||
cnt++;
|
// std::cerr << "length ratio of x after each step"
|
||||||
|
// << (double)x.num_length / (double)L1 << std::endl;
|
||||||
|
// cnt++;
|
||||||
}
|
}
|
||||||
/*ret=A*x/10^(L1)*/
|
/*ret=A*x/10^(L1)*/
|
||||||
UnsignedMultiply(x, &A);
|
UnsignedMultiply(x, &A);
|
||||||
@ -591,7 +595,7 @@ inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
|
|||||||
UnsignedAdd(x, &kOne);
|
UnsignedAdd(x, &kOne);
|
||||||
// cnt++;
|
// cnt++;
|
||||||
}
|
}
|
||||||
std::cerr << cnt << std::endl;
|
// std::cerr << cnt << std::endl;
|
||||||
A = std::move(x);
|
A = std::move(x);
|
||||||
}
|
}
|
||||||
int2048 &int2048::Divide(const int2048 &B) {
|
int2048 &int2048::Divide(const int2048 &B) {
|
||||||
|
@ -36,7 +36,7 @@ opt_python=[]
|
|||||||
|
|
||||||
if True:
|
if True:
|
||||||
for i in range(0,10):
|
for i in range(0,10):
|
||||||
val=randint(-10**2,10**2)
|
val=randint(-10**100,10**100)
|
||||||
opt_cpp.append("a_"+str(i)+"=int2048(\""+str(val)+"\");")
|
opt_cpp.append("a_"+str(i)+"=int2048(\""+str(val)+"\");")
|
||||||
opt_python.append("a_"+str(i)+"="+str(val))
|
opt_python.append("a_"+str(i)+"="+str(val))
|
||||||
opt_cpp.append("a_"+str(i)+".print(); puts(\"\");")
|
opt_cpp.append("a_"+str(i)+".print(); puts(\"\");")
|
||||||
|
Reference in New Issue
Block a user