高精度板子

2022-03-06 13:16:13 字數 1778 閱讀 3057

//#include#include#include#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;

const int max=10001;

struct hp;

// num[0]用來儲存數字位數。利用10000進製可以節省空間和時間。

hp&hp::operator=(const char* c)

num[0]=j;

return *this;

}hp&hp::operator=(int a)

hp::hp()

hp::hp(int n)// 目的:支援「hp a=1;」之類的**。

// 如果位數不等,大小是可以明顯看出來的。如果位數相等,就需要逐位比較。

bool hp::operator > (const hp &b) const

bool hp::operator<(const hp &b)const

bool hp::operator<=(const hp &b)const

bool hp::operator>=(const hp &b)const

bool hp::operator!=(const hp &b)const

bool hp::operator==(const hp &b)const

// 注意:最高位的位置和位數要匹配。

//加法

hp hp::operator+(const hp&b)const

}if(c.num[c.num[0]+1]>0) c.num[0]++;// 9999+1,計算完成後多了一位

return c;

}//減法

hp hp::operator-(const hp&b)const

}while(c.num[c.num[0]]==0&&c.num[0]>1) c.num[0]--;// 100000000-99999999

return c;

}//順便宣告

hp&hp::operator+=(const hp &b)

hp&hp::operator-=(const hp &b)

//乘法

hp hp::operator*(const hp&b)const

}while(c.num[c.num[0]]==0&&c.num[0]>1) c.num[0]--; // 99999999*0

return c;

}//同上

hp&hp::operator*=(const hp &b)

hp hp::operator/(const hp&b)const

hp hp::operator%(const hp&b)const

hp&hp::operator/=(const hp &b)

hp&hp::operator%=(const hp &b)

inline hp power(hp x,hp y)

return result;

}inline hp sqrt(hp x,hp y)

return l-1;

}inline hp factorial(hp x)

istream & operator>>(istream &in, hp &n)

ostream&operator<<(ostream &o,hp n)

return ans*flag;

}int main()

高精度板子

include include include include include include include include include include include include include include include include include include using ...

高精度板子

乘法學會fft以後,應該乘除都能優化很多。include include include include using namespace std int mi 28 const int maxlen 2e5 16,maxbit 1e8 int max int a,int b void plus1 並...

高精度板子

本章即將介紹的是一章高精度的板子,並沒有深奧的道理,大函式大 inline 者,暫且靠邊站,筆者沒有那麼高水平,滿足不了這些需求。本文如有理念上與邏輯上的錯誤,請多多包涵並且指出。什麼是高精度?高精度,雖然聽起來感覺很生熟,很深奧,但是,原理不過是小學二三年級時的加減法豎式和四五年級的乘法算式罷了,...