#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL; struct Bign
{
static const int BASE=;
static const int WIDTH=;
vector<int>s; Bign(LL n=){*this=n;}
Bign(const string& str){*this=str;}
Bign operator =(LL n)
{
s.clear();
do
{
s.push_back(n%BASE);
n/=BASE;
}while(n>);
return *this;
}
Bign operator =(const string& str)
{
s.clear();
int x,len=(str.length()-)/WIDTH+;
for(int i=;i<len;i++)
{
int end=str.length()-i*WIDTH;
int start=max(,end-WIDTH);
sscanf(str.substr(start,end-start).c_str(),"%d",&x);
s.push_back(x);
}
return *this;
}
Bign operator +(const Bign& b)const
{
int len1=s.size(),len2=b.s.size();
int len=max(len1,len2);
int ans=;
Bign c;c.s.clear();
for(int i=;i<len||ans!=;i++)
{
if(i<len1) ans+=s[i];
if(i<len2) ans+=b.s[i];
c.s.push_back(ans%BASE);
ans/=BASE;
}
return c;
}
Bign operator -(const Bign& b)const
{ int len1=s.size(),len2=b.s.size();
Bign c;c.s.clear();
int ans=,t=;
for(int i=;i<len1;i++)
{
if(i<len2) ans=s[i]-b.s[i]+t;
else ans=s[i]+t;
if(ans<)
{
ans+=BASE;t=-;
}
else t=;
if(ans>)c.s.push_back(ans);
}
return c;
}
Bign operator *(const Bign& b)const
{
Bign c;
int len1=s.size(),len2=b.s.size();
for(int i=;i<len2;i++)
{
for(int j=;j<len1;j++)
{
Bign ans=(LL)b.s[i]*s[j];
for(int k=;k<i+j;k++)
ans.s.insert(ans.s.begin(),);
c=c+ans;
}
}
return c;
} bool operator <(const Bign& b)const
{
if(s.size()!=b.s.size()) return s.size()<b.s.size();
for(int i=s.size()-;i>=;i--)
if(s[i]!=b.s[i]) return s[i]<b.s[i];
return false;
}
bool operator ==(const Bign& b)const
{
if(s.size()!=b.s.size()) return false;
for(int i=s.size()-;i>=;i--)
if(s[i]!=b.s[i]) return false;
return true;
}
};
ostream& operator <<(ostream& out,const Bign& a)
{
out<<a.s.back();
char buf[];
int len=a.s.size();
for(int i=len-;i>=;i--)
{
sprintf(buf,"%08d",a.s[i]);
out<<buf;
}
return out;
}
LL BtoL(const Bign& a)
{
LL c;
char buf[];
string ss="";
int len=a.s.size();
sprintf(buf,"%d",a.s.back());ss+=(string)buf;
for(int i=len-;i>=;i--)
{
sprintf(buf,"%08d",a.s[i]);
ss+=(string)buf;
}
sscanf(ss.c_str(),"%lld",&c);
return c;
}
istream& operator >>(istream& in,Bign& a)
{
string s;
in>>s;
a=s;
return in;
}

模板——BigInteger的更多相关文章

  1. POJ 1625 Censored!(AC自动机->指针版+DP+大数)题解

    题目:给你n个字母,p个模式串,要你写一个长度为m的串,要求这个串不能包含模式串,问你这样的串最多能写几个 思路:dp+AC自动机应该能看出来,万万没想到这题还要加大数...orz 状态转移方程dp[ ...

  2. 模板-高精度BigInteger

    #include <bits/stdc++.h> using namespace std; struct BigInteger { static const int BASE = 1000 ...

  3. C++ BigInteger 大整数类模板(转)

    #include <deque> #include <vector> #include <iostream> #include <string> #in ...

  4. 【Java】-BigInteger大数类的使用【超强Java大数模板 总结】

    Scanner cin = new Scanner(new BufferedInputStream(System.in)); 这样定义Scanner类的对象读入数据可能会快一些! 参考这个博客继续补充 ...

  5. C++ BigInteger模板

    #include <cstdio> #include <cstring> #include <string> #include <iostream> # ...

  6. BigInteger

    首先上模板(不断更新中...)(根据刘汝佳AOAPCII修改) #include <iostream> #include <sstream> #include <cstd ...

  7. 高精度模板 Luogu P1932 A+B & A-B & A*B & A/B Problem

    P1932 A+B & A-B & A*B & A/B Problem 题目背景 这个题目很新颖吧!!! 题目描述 求A.B的和差积商余! 输入输出格式 输入格式: 两个数两行 ...

  8. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...

  9. 大数模板 poj3982

    1. 这个模板不是自己写的,转载的别人转载的,还没学完c++的我,想写也没有那能力. 这个模板我用在了POJ的一道题上,传送门--POJ3982 一般大数的题,都可用这个模板解决,仅仅须要改动主函数就 ...

随机推荐

  1. 【模板】树的重心 洛谷P1364 医院设置

    P1364 医院设置 题目描述 设有一棵二叉树,如图: 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接 ...

  2. Leetcode762.Prime Number of Set Bits in Binary Representation二进制表示中质数个计算置位

    给定两个整数 L 和 R ,找到闭区间 [L, R] 范围内,计算置位位数为质数的整数个数. (注意,计算置位代表二进制表示中1的个数.例如 21 的二进制表示 10101 有 3 个计算置位.还有, ...

  3. Xdebug步骤

    谷歌浏览器安装xdebug cd  /etc/php/7.2/fpm/conf.d 重启sudo service php7.1-fpm restart   (注意 php版本) 重启编辑器

  4. V8引擎实现标准ECMA-262(三)

    推荐英文原址ECMA-262 3.构造函数 构造函数除了通过指定的模式创建对象以外,还有另外一个好处--它能够自动设置新创建对象的原型对象,这个原型对象存储在构造函数的Prototype属性中. 例如 ...

  5. Oracle之PL/SQL编程

    PL/SQL(Procedural Language/SQL,过程语言/SQL) 是结合了Oracel过程语言和结构化查询语言(SQL)的一种扩展语言. 优点: (1)PL/SQL具有编程语言的特点, ...

  6. 【时光回溯】【JZOJ3568】【GDKOI2014】小纪的作业题

    题目描述 输入 输出 有M行,每个询问一行,输出结果mod 1,000,000,007的值. 样例输入 10 3 3 5 1 2 3 1 3 5 2 1 7 9 3 9 2 3 样例输出 10 19 ...

  7. python ASCII编码集

  8. Java练习 SDUT-2749_区域内点的个数

    区域内点的个数 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description X晚上睡不着的时候不喜欢玩手机,也不喜欢打游戏,他喜欢数 ...

  9. 从入侵到变现——“黑洞”下的黑帽SEO分析

    概述 由于互联网入口流量主要被搜索引擎占据,网站在搜索引擎中的排名直接影响到市场营销效果,因此SEO服务应运而生.SEO(Search Engine Optimization)全称为搜索引擎优化,是指 ...

  10. Creating a Pulsing Circle Animation

    原文 https://www.kirupa.com/animations/creating_pulsing_circle_animation.htm Outside of transitions th ...