本文整理汇总了C++中Bigint类的典型用法代码示例。如果您正苦于以下问题:C++ Bigint类的具体用法?C++ Bigint怎么用?C++ Bigint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bigint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
Bigint arr[5],tmp[5];
int T;
scanf("%d",&T);
while(T--)
{
arr[1] = "1"; arr[2] = "1"; arr[3] = "1"; arr[4] = "1";
int N;
scanf("%d",&N);
if(N == 0) { printf("0\n"); continue; }
for(int i = 2 ; i <= N ; i++)
{
tmp[1] = arr[1]; tmp[2] = arr[2]; tmp[3] = arr[3]; tmp[4] = arr[4];
arr[1] = "0"; arr[2] = "0"; arr[3] = "0"; arr[4] = "0";
arr[2] = arr[2] + tmp[1];
arr[1] = arr[1] + tmp[2]; arr[3] = arr[3] + tmp[2];
arr[4] = arr[4] + tmp[3];
arr[3] = arr[3] + tmp[4]; arr[2] = arr[2] + tmp[4];
}
//printf("%d\t%d\t%d\t%d\t\n",arr[1],arr[2],arr[3],arr[4]);
Bigint sum = arr[1]+arr[2]+arr[3]+arr[4];
sum.print();
printf("\n");
}
return 0;
}
示例2: strlen
Bigint::Bigint(const Bigint &big)
{
int nlen = strlen(big.getptr());
m_pnum = new char[nlen +1];
memset(m_pnum, 0, nlen + 1);
strcpy_s(m_pnum, nlen +1, big.getptr());
}
示例3: cp3
int cp3(const Bigint &b)const {
if (s != b.s) return s > b.s;
if (s == -1) return -(-*this).cp3(-b);
if (len() != b.len()) return len()>b.len()?1:-1;
for (int i=len()-1; i>=0; i--)
if (v[i]!=b.v[i]) return v[i]>b.v[i]?1:-1;
return 0;
}
示例4: cp3
int cp3(const Bigint &b)const {
if (s != b.s) return s - b.s;
if (s == -1) return -(-*this).cp3(-b);
if (len() != b.len()) return len()-b.len();//int
for (int i=len()-1; i>=0; i--)
if (v[i]!=b.v[i]) return v[i]-b.v[i];
return 0;
}
示例5: divmod
pair<Bigint, int> divmod(Bigint a, int m) {
long long r = 0;
for (int i = a.len() - 1; i >= 0; i--) {
r = r * BASE + a[i];
a[i] = r / m;
r %= m;
}
a.trim();
return make_pair(a, (int) r);
}
示例6:
Bigint operator + ( Bigint b ) {
if( sign != b.sign ) return (*this) - b.inverseSign();
Bigint c;
for(int i = 0, carry = 0; i<a.size() || i<b.size() || carry; i++ ) {
carry+=(i<a.size() ? a[i]-48 : 0)+(i<b.a.size() ? b.a[i]-48 : 0);
c.a += (carry % 10 + 48);
carry /= 10;
}
return c.normalize(sign);
}
示例7: bigcmp
int bigcmp(const Bigint& num1, const Bigint& num2)
{
int nlen1 = num1.getlength(), nlen2 = num2.getlength();
if(nlen1 > nlen2) return 1;
if(nlen1 < nlen2) return -1;
return strcmp(num1.getptr(), num2.getptr());
}
示例8:
Bigint operator - ( Bigint b ) {
if( sign != b.sign ) return (*this) + b.inverseSign();
if( (*this) < b ) return (b - (*this)).inverseSign();
Bigint c;
for( int i = 0, borrow = 0; i < (int)a.size(); i++ ) {
borrow = a[i] - borrow - (i < b.size() ? b.a[i] : 48);
c.a += borrow >= 0 ? borrow + 48 : borrow + 58;
borrow = borrow >= 0 ? 0 : 1;
}
return c.normalize(sign);
}
示例9:
Bigint operator * (Bigint a, int m) {
long long r = 0;
for (int i = 0; i < a.len(); i++) {
r += (long long) a[i] * m;
a[i] = r % BASE;
r /= BASE;
}
while (r) a.data.push_back(r % BASE), r /= BASE;
a.trim();
return a;
}
示例10:
Bigint operator - ( Bigint b ) { // subtraction operator overloading
if( sign != b.sign ) return (*this) + b.inverseSign();
int s = sign; sign = b.sign = 1;
if( (*this) < b ) return ((b - (*this)).inverseSign()).normalize(-s);
Bigint c;
for( int i = 0, borrow = 0; i < a.size(); i++ ) {
borrow = a[i] - borrow - (i < b.size() ? b.a[i] : 48);
c.a += borrow >= 0 ? borrow + 48 : borrow + 58;
borrow = borrow >= 0 ? 0 : 1;
}
return c.normalize(s);
}
示例11: main
int main() {
Bigint n, m;
string a, b;
while (cin >> a >> b) {
n = a; m = b;
Bigint sum;
sum = fact(n) + fact(m);
sum.print();
cout << endl;
}
return 0;
}
示例12: internalDivide
void Bigint::internalDivide(const Bigint& number, const bool& isDecimal, const int& precision)
{
std::string mstring;
std::vector<int> mparts;
std::string fnvalue = toString();
std::string snvalue = number.toString();
if(fnvalue.length()>snvalue.length())
{
if(!number.isPositive)
mstring = snvalue.substr(1);
else
mstring = snvalue;
mparts = parts;
}
else
{
if(!number.isPositive)
mstring = fnvalue.substr(1);
else
mstring = fnvalue;
mparts = number.parts;
}
if(mstring!="" && mparts.size()>0)
{
int recurse = 0;
std::string build;
decompose(fnvalue, snvalue, number, recurse, build, isDecimal, precision);
try {
create(build);
} catch (...) {
}
}
}
示例13:
Bigint operator * (const Bigint &b) {
Bigint r;
r.resize(len() + b.len() + 1);
r.s = s * b.s;
for (int i=0; i<len(); i++) {
for (int j=0; j<b.len(); j++) {
r.v[i+j] += v[i] * b.v[j];
if(r.v[i+j] >= BIGMOD) {
r.v[i+j+1] += r.v[i+j] / BIGMOD;
r.v[i+j] %= BIGMOD;
}
}
}
r.n();
return r;
}
示例14:
Bigint operator - (const Bigint &b) const {
if(s == -1) return -(-(*this)-(-b));
if(b.s == -1) return (*this)+(-b);
if((*this)<b) return -(b-(*this));
Bigint r;
r.l=l;
for(int i=0;i<l;i++) {
r.v[i]+=v[i];
if(i<b.l) r.v[i]-=b.v[i];
if(r.v[i]<0) {
r.v[i]+=bM;
r.v[i+1]--;
}
}
r.n();
return r;
}
示例15: max
Bigint operator + (const Bigint &b) const {
if (s == -1) return -(-(*this)+(-b));
if (b.s == -1) return (*this)-(-b);
Bigint r;
int nl = max(len(), b.len());
r.resize(nl + 1);
for (int i=0; i<nl; i++) {
if (i < len()) r.v[i] += v[i];
if (i < b.len()) r.v[i] += b.v[i];
if(r.v[i] >= BIGMOD) {
r.v[i+1] += r.v[i] / BIGMOD;
r.v[i] %= BIGMOD;
}
}
r.n();
return r;
}