__int1024!
使用说明:
- 数据范围约为\(-2^{1024}\le N \le2^{1024}\),反映到十进制约为\(-10^{309}\le N \le10^{309}\),但不保证完全如此。
- 输入输出使用自带的输入及输出函数。由于其内部用
scanf和printf来实现,所以请不要把它与ios::sync_with_stdio(false)同时使用。 - 由于内部采用高精度实现,所以复杂度不可忽略。具体复杂度会在下面列出。
- 特别地,自增及自减运算只能放在变量前面。如置于后面会报错。
支持操作: - 输入输出。使用
.in()和.out()即可。 - 运算。支持
+,-,*,/,%``++``--共七种运算,类比int使用即可。 - 赋值。直接使用
=即可。 - 比较关系。支持
>,>=,<,<=,==,!=共六种运算,类比int使用即可。
头文件&宏定义:
宏定义不喜可换。
#include<iostream>
#include<string.h>
using namespace std;
#define il inline
#define ri register int
正片:
因为本来就没想让别人读懂所以一点注释都没加。
struct __int1024
{
string zp;
il void out()
{
int h=0;
if(zp[h]=='-')
{
printf("%c",zp[h]);
h++;
}
while(zp[h]>='0'&&zp[h]<='9')
{
printf("%c",zp[h]);
h++;
}
return;
}
il void in()
{
char c=' ';
while(scanf("%c",&c)!=EOF)
{
if(c=='+'||c=='-')
{
break;
}
if(c>='0'&&c<='9')
{
break;
}
}
if(c=='-')
{
zp.push_back(c);
}
if(c>='0'&&c<='9')
{
zp.push_back(c);
}
while(scanf("%c",&c)!=EOF)
{
if(c=='+')
{
continue;
}
if(c=='-')
{
zp.push_back(c);
continue;
}
if(c>='0'&&c<='9')
{
zp.push_back(c);
continue;
}
break;
}
return;
}
il bool dayu(__int1024 x,__int1024 y)
{
if(x.zp[0]=='-'&&y.zp[0]=='-')
{
__int1024 m,n;
int u=x.zp.size(),v=x.zp.size();
m.zp=x.zp.substr(1,u-1);
n.zp=y.zp.substr(1,v-1);
return dayu(n,m);
}
if(x.zp[0]=='-')
{
return false;
}
if(y.zp[0]=='-')
{
return true;
}
if(x.zp.size()>y.zp.size())
{
return true;
}
if(x.zp.size()<y.zp.size())
{
return false;
}
for(ri i=0;i<x.zp.size();i++)
{
if(x.zp[i]>y.zp[i])
{
return true;
}
if(x.zp[i]<y.zp[i])
{
return false;
}
}
return false;
}
il bool xiaoyu(__int1024 x,__int1024 y)
{
if(x.zp[0]=='-'&&y.zp[0]=='-')
{
__int1024 m,n;
int u=x.zp.size(),v=x.zp.size();
m.zp=x.zp.substr(1,u-1);
n.zp=y.zp.substr(1,v-1);
return xiaoyu(n,m);
}
if(x.zp[0]=='-')
{
return true;
}
if(y.zp[0]=='-')
{
return false;
}
if(x.zp.size()<y.zp.size())
{
return true;
}
if(x.zp.size()>y.zp.size())
{
return false;
}
for(ri i=0;i<x.zp.size();i++)
{
if(x.zp[i]<y.zp[i])
{
return true;
}
if(x.zp[i]>y.zp[i])
{
return false;
}
}
return false;
}
il bool dengyu(__int1024 x,__int1024 y)
{
if(x.zp.size()!=y.zp.size())
{
return false;
}
for(ri i=0;i<x.zp.size();i++)
{
if(x.zp[i]!=y.zp[i])
{
return false;
}
}
return true;
}
il __int1024 jia(__int1024 x,__int1024 y)
{
string rn;
__int1024 qm;
int u=x.zp.size(),v=y.zp.size(),w;
if(x.zp[0]=='-'&&y.zp[0]=='-')
{
__int1024 m,n,z;
m.zp=x.zp.substr(1,u-1);
n.zp=y.zp.substr(1,v-1);
z=jia(m,n);
if(z.zp[0]=='-')
{
rn=z.zp.substr(1,z.zp.size()-1);
}
else
{
rn.resize(1,'-');
rn+=z.zp;
}
qm.zp=rn;
return qm;
}
if(x.zp[0]=='-')
{
__int1024 z;
z.zp=x.zp.substr(1,u-1);
return jian(y,z);
}
if(y.zp[0]=='-')
{
__int1024 z;
z.zp=y.zp.substr(1,v-1);
return jian(x,z);
}
int o[310],p[310],q[310];
memset(o,0,sizeof(o));
memset(p,0,sizeof(p));
memset(q,0,sizeof(q));
for(ri i=0,j=u;j>0;i++,j--)
{
p[j]=x.zp[i]-'0';
}
for(ri i=0,j=v;j>0;i++,j--)
{
q[j]=y.zp[i]-'0';
}
w=max(u,v);
for(ri i=1;i<=w+1;i++)
{
int j=p[i]+q[i];
o[i]+=j;
o[i+1]+=o[i]/10;
o[i]%=10;
}
if(o[w+1]!=0)
{
w++;
}
rn.resize(w,'0');
for(ri i=0,j=w;j>0;i++,j--)
{
rn[i]+=o[j];
}
qm.zp=rn;
return qm;
}
il __int1024 jian(__int1024 x,__int1024 y)
{
__int1024 qm;
string rn;
int u=x.zp.size(),v=y.zp.size(),w;
if(x.zp[0]=='-'&&y.zp[0]=='-')
{
__int1024 m,n,z;
m.zp=x.zp.substr(1,u-1);
n.zp=y.zp.substr(1,v-1);
z=jian(m,n);
w=z.zp.size();
if(z.zp[0]=='-')
{
rn=z.zp.substr(1,w-1);
}
else
{
rn.resize(1,'-');
rn+=z.zp;
}
qm.zp=rn;
return qm;
}
if(y.zp[0]=='-')
{
__int1024 z;
z.zp=y.zp.substr(1,v-1);
return jia(x,z);
}
if(x.zp[0]=='-')
{
__int1024 z,t;
z.zp=x.zp.substr(1,u-1);
t=jia(z,y);
qm.zp.resize(1,'-');
qm.zp+=t.zp;
return qm;
}
if(dayu(x,y)==false&&dengyu(x,y)==false)
{
__int1024 m,n,z;
m.zp=x.zp;
n.zp=y.zp;
z=jian(n,m);
w=z.zp.size();
if(z.zp[0]=='-')
{
rn=z.zp.substr(1,w-1);
}
else
{
rn.resize(1,'-');
rn+=z.zp;
}
qm.zp=rn;
return qm;
}
int o[310],p[310],q[310];
memset(o,0,sizeof(o));
memset(p,0,sizeof(p));
memset(q,0,sizeof(q));
for(ri i=0,j=u;j>0;i++,j--)
{
p[j]=x.zp[i]-'0';
}
for(ri i=0,j=v;j>0;i++,j--)
{
q[j]=y.zp[i]-'0';
}
for(ri i=1;i<=u;i++)
{
int j=p[i]-q[i];
o[i]+=j;
o[i+1]+=o[i]/10;
o[i]%=10;
if(o[i]<0)
{
o[i]+=10;
o[i+1]-=1;
}
}
while(o[u]==0&&u!=1)
{
u--;
}
rn.resize(u,'0');
for(ri i=0,j=u;j>0;i++,j--)
{
rn[i]+=o[j];
}
qm.zp=rn;
return qm;
}
il __int1024 cheng(__int1024 x,__int1024 y)
{
string rn;
__int1024 qm;
int u=x.zp.size(),v=y.zp.size(),w;
if(x.zp[0]=='-'&&y.zp[0]=='-')
{
__int1024 m,n;
m.zp=x.zp.substr(1,u-1);
n.zp=y.zp.substr(1,v-1);
return cheng(m,n);
}
if(x.zp[0]=='-'||y.zp[0]=='-')
{
__int1024 m,n,z;
m.zp=x.zp.substr(1,u-1);
n.zp=y.zp.substr(1,v-1);
z=cheng(m,n);
if(z.zp[0]=='-')
{
rn=z.zp.substr(1,z.zp.size()-1);
}
else
{
rn.resize(1,'-');
rn+=z.zp;
}
qm.zp=rn;
return qm;
}
int o[310],p[310],q[310];
memset(o,0,sizeof(o));
memset(p,0,sizeof(p));
memset(q,0,sizeof(q));
for(ri i=0,j=u;j>0;i++,j--)
{
p[j]=x.zp[i]-'0';
}
for(ri i=0,j=v;j>0;i++,j--)
{
q[j]=y.zp[i]-'0';
}
w=u+v;
for(ri i=1;i<=u;i++)
{
for(ri j=1;j<=v;j++)
{
int k=p[i]*q[j];
o[i+j-1]+=k;
o[i+j]+=o[i+j-1]/10;
o[i+j-1]%=10;
}
}
while(o[w]==0&&w!=1)
{
w--;
}
rn.resize(w,'0');
for(ri i=0,j=w;j>0;i++,j--)
{
rn[i]+=o[j];
}
qm.zp=rn;
return qm;
}
il __int1024 chu(__int1024 x,__int1024 y)
{
string rn;
__int1024 qm;
int u=x.zp.size(),v=y.zp.size();
if(x.zp[0]=='-'&&y.zp[0]=='-')
{
__int1024 m,n;
m.zp=x.zp.substr(1,u-1);
n.zp=y.zp.substr(1,v-1);
return chu(m,n);
}
if(x.zp[0]=='-')
{
__int1024 m,z;
m.zp=x.zp.substr(1,u-1);
z=chu(m,y);
if(z.zp[0]=='-')
{
rn=z.zp.substr(1,z.zp.size()-1);
}
else
{
rn.resize(1,'-');
rn+=z.zp;
}
qm.zp=rn;
return qm;
}
if(y.zp[0]=='-')
{
__int1024 n,z;
n.zp=y.zp.substr(1,v-1);
z=chu(x,n);
if(z.zp[0]=='-')
{
rn=z.zp.substr(1,z.zp.size()-1);
}
else
{
rn.resize(1,'-');
rn+=z.zp;
}
qm.zp=rn;
return qm;
}
if(dayu(x,y)==false&&dengyu(x,y)==false)
{
qm.zp="0";
return qm;
}
int o[310],p[310],q[310];
memset(o,0,sizeof(o));
memset(p,0,sizeof(p));
memset(q,0,sizeof(q));
for(ri i=0;i<u;i++)
{
p[i+1]=x.zp[i]-'0';
}
for(ri i=0;i<u;i++)
{
q[i+1]=y.zp[i]-'0';
}
int rt=1;
for(ri i=1;i<=u;i++)
{
if(rt>i)
{
o[i]=0;
continue;
}
string al=x.zp.substr(0,i-rt+1);
__int1024 z;
z.zp=al;
if(dayu(y,z)==true)
{
o[i]=0;
continue;
}
int m=1,n=9;
while(n-m>1)
{
char l=((m+n)>>1)+'0';
__int1024 wn;
wn.zp.push_back(l);
if(dayu(cheng(y,wn),z)==true)
{
n=l-'0'-1;
}
else
{
m=l-'0';
}
}
char l=n+'0';
__int1024 wn,xo;
wn.zp.push_back(l);
if(dayu(cheng(y,wn),z)==false)
{
o[i]=n;
wn.zp[0]=n+'0';
xo=cheng(wn,y);
for(ri j=i+1;j<=u;j++)
{
xo.zp.push_back('0');
}
int sk=x.zp.size();
x=jian(x,xo);
rt+=sk-x.zp.size();
}
else
{
o[i]=m;
wn.zp[0]=m+'0';
xo=cheng(wn,y);
for(ri j=i+1;j<=u;j++)
{
xo.zp.push_back('0');
}
int sk=x.zp.size();
x=jian(x,xo);
rt+=sk-x.zp.size();
}
}
int w=1;
while(o[w]==0&&w!=u)
{
w++;
}
rn.resize(u-w+1,'0');
for(ri i=0,j=w;j<=u;i++,j++)
{
rn[i]+=o[j];
}
qm.zp=rn;
return qm;
}
__int1024 zjia(__int1024 x)
{
string rn;
if(x.zp[0]=='-')
{
__int1024 y,z;
y.zp=x.zp.substr(1,x.zp.size());
z=zjian(y);
if(z.zp[0]!='0')
{
rn=z.zp;
z.zp='-';
z.zp+=rn;
}
return z;
}
int h=x.zp.size()-1;
while(x.zp[h]=='9'&&h>=0)
{
x.zp[h]='0';
h--;
}
if(h<0)
{
rn=x.zp;
x.zp='1';
x.zp+=rn;
}
else
{
x.zp[h]+=1;
}
return x;
}
__int1024 zjian(__int1024 x)
{
string rn;
if(x.zp[0]=='0')
{
x.zp="-1";
return x;
}
if(x.zp[0]=='-')
{
__int1024 y,z;
y.zp=x.zp.substr(1,x.zp.size());
z=zjia(y);
if(z.zp[0]!='0')
{
rn=z.zp;
z.zp='-';
z.zp+=rn;
}
return z;
}
int h=x.zp.size()-1;
while(x.zp[h]=='0'&&h>=0)
{
x.zp[h]='9';
h--;
}
if(h<0)
{
rn=x.zp.substr(1,x.zp.size()-1);
x.zp+=rn;
}
else
{
x.zp[h]-=1;
}
return x;
}
__int1024 operator +(const __int1024 &A)
{
return jia(*this,A);
}
__int1024 operator -(const __int1024 &A)
{
return jian(*this,A);
}
__int1024 operator*(const __int1024 &A)
{
return cheng(*this,A);
}
__int1024 operator/(const __int1024 &A)
{
return chu(*this,A);
}
__int1024 operator%(const __int1024 &A)
{
return jian(*this,cheng(A,chu(*this,A)));
}
void operator++()
{
*this=zjia(*this);
}
void operator--()
{
*this=zjian(*this);
}
void operator =(const __int1024 &A)
{
zp=A.zp;
return;
}
bool operator >(const __int1024 &A)
{
return dayu(*this,A);
}
bool operator <(const __int1024 &A)
{
return xiaoyu(*this,A);
}
bool operator ==(const __int1024 &A)
{
return dengyu(*this,A);
}
bool operator >=(const __int1024 &A)
{
return (dayu(*this,A)||dengyu(*this,A));
}
bool operator <=(const __int1024 &A)
{
return (xiaoyu(*this,A)||dengyu(*this,A));
}
bool operator !=(const __int1024 &A)
{
return (dengyu(*this,A)==true)?false:true;
}
};
后记:
想学高精建议打P1932。
__int65536正加紧制作中!
随机推荐
- dotnet 8 破坏性改动 在 AssemblyInformationalVersionAttribute 添加上 git 的 commit 号
我在一个 WPF 项目里面,在界面显示应用的版本号,更新到 dotnet 8 的 SDK 之后,发现我的界面布局损坏了.本质上这个破坏性改动和 WPF 没有什么关系,是 dotnet 的 SDK 或编 ...
- Linux内核之I2C协议
I2C协议标准文档 THE I2C-BUS SPECIFICATION VERSION 2.1 JANUARY 2000: https://www.csd.uoc.gr/~hy428/reading/ ...
- 升级版header吸顶后滑动变色(二)
<van-nav-bar fixed id="opacityHeader" //拉伸状态显示的header title="赛事" ...
- virutalenvwrapper安装和使用
目录 virutalenvwrapper安装和使用 目的: 1.安装pip 2.安装virutalenv和virutalenvwrapper 3.配置环境变量 4. 创建虚拟环境 5.列出全部的虚拟环 ...
- 使用.NET源生成器(SG)实现一个自动注入的生成器
DI依赖注入对我们后端程序员来说肯定是基础中的基础了,我们经常会使用下面的代码注入相关的service services.AddScoped<Biwen.AutoClassGen.TestCon ...
- ansible系列(30)--ansible的role详解
目录 1. Ansible Roles 1.1 roles目录结构 1.2 roles编写步骤 1.2.1 编写基本的roles 1.2.2 roles的调用 1.2.3 roles中使用变量 1.2 ...
- C数据结构:树和森林存储方式与遍历方式
文章目录 树的存储方式 双亲表示法 孩子链表表示法 孩子兄弟表示法(二叉树表示法) 树和二叉树的转换 森林和二叉树的转换 树和森林的遍历 树的遍历方式 森林的遍历方式 浅谈一下几个问题 为什么树没有中 ...
- 初识上位机(下):C#读写PLC数据块数据
大家好,我是Edison. 作为一个工业自动化领域的程序员,不懂点PLC和上位机,貌似有点说不过去.这里我用两篇小文带你快速进入上位机开发领域.后续,我会考虑再出一个系列文章一起玩工控上位机. 上一篇 ...
- kubernetes 之dashboard
部署 kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recomme ...
- MLP实现波士顿房屋价格回归任务
1. 数据集 波士顿房屋价格.csv文件,文件中的数据有可能不完整,部分数据如下: CRIM, ZN ,INDUS ,CHAS,NOX,RM,AGE,DIS,RAD,TAX,PTRATIO,LSTAT ...