da shu mo ban
#include<bits/stdc++.h>
using namespace std;
const int maxn=;/*精度位数,自行调整*/
//1.如果需要控制输出位数的话,在str()里面把len调成需要的位数
//2.很大的位数是会re的,所以如果是幂运算的话,如 计算x^p的位数n, n=p*log(10)x+1;(注意要加一)
//3.还可以加上qmul,取模的过程也就是str(),c_str()再搞一次
class bign
{
//io*2 bign*5*2 bool*6
friend istream& operator>>(istream&,bign&);
friend ostream& operator<<(ostream&,const bign&);
friend bign operator+(const bign&,const bign&);
friend bign operator+(const bign&,int&);
friend bign operator*(const bign&,const bign&);
friend bign operator*(const bign&,int&);
friend bign operator-(const bign&,const bign&);
friend bign operator-(const bign&,int&);
friend bign operator/(const bign&,const bign&);
friend bign operator/(const bign&,int&);
friend bign operator%(const bign&,const bign&);
friend bign operator%(const bign&,int&);
friend bool operator<(const bign&,const bign&);
friend bool operator>(const bign&,const bign&);
friend bool operator<=(const bign&,const bign&);
friend bool operator>=(const bign&,const bign&);
friend bool operator==(const bign&,const bign&);
friend bool operator!=(const bign&,const bign&); private://如果想访问len,改成public
int len,s[maxn];
public:
bign()
{
memset(s,,sizeof(s));
len=;
}
bign operator=(const char* num)
{
int i=,ol;
ol=len=strlen(num);
while(num[i++]==''&&len>)
len--;
memset(s,,sizeof(s));
for(i=; i<len; i++)
s[i]=num[ol-i-]-'';
return *this;
}
bign operator=(int num)
{
char s[maxn];
sprintf(s,"%d",num);
*this=s;
return *this;
}
bign(int num)
{
*this=num;
}
bign(const char* num)
{
*this=num;
}
string str() const
{
string res="";
for(int i=; i<len; i++)
res=char(s[i]+'')+res;
if(res=="")
res="";
return res;
}
};
bool operator<(const bign& a,const bign& b)
{
int i;
if(a.len!=b.len)
return a.len<b.len;
for(i=a.len-; i>=; i--)
if(a.s[i]!=b.s[i])
return a.s[i]<b.s[i];
return false;
}
bool operator>(const bign& a,const bign& b)
{
return b<a;
}
bool operator<=(const bign& a,const bign& b)
{
return !(a>b);
}
bool operator>=(const bign& a,const bign& b)
{
return !(a<b);
}
bool operator!=(const bign& a,const bign& b)
{
return a<b||a>b;
}
bool operator==(const bign& a,const bign& b)
{
return !(a<b||a>b);
}
bign operator+(const bign& a,const bign& b)
{
int up=max(a.len,b.len);
bign sum;
sum.len=;
for(int i=,t=;t||i<up; i++)
{
if(i<a.len)
t+=a.s[i];
if(i<b.len)
t+=b.s[i];
sum.s[sum.len++]=t%;
t/=;
}
return sum;
}
bign operator+(const bign& a,int& b)
{
bign c=b;
return a+c;
}
bign operator*(const bign& a,const bign& b)
{
bign res;
for(int i=; i<a.len; i++)
{
for(int j=; j<b.len; j++)
{
res.s[i+j]+=(a.s[i]*b.s[j]);
res.s[i+j+]+=res.s[i+j]/;
res.s[i+j]%=;
}
}
res.len=a.len+b.len;
while(res.s[res.len-]==&&res.len>)
res.len--;
if(res.s[res.len])
res.len++;
return res;
}
bign operator*(const bign& a,int& b)
{
bign c=b;
return a*c;
}
//只支持大数减小数
bign operator-(const bign& a,const bign& b)
{
bign res;
int len=a.len;
for(int i=; i<len; i++)
{
res.s[i]+=a.s[i]-b.s[i];
if(res.s[i]<)
{
res.s[i]+=;
res.s[i+]--;
}
}
while(res.s[len-]==&&len>)
len--;
res.len=len;
return res;
}
bign operator-(const bign& a,int& b)
{
bign c=b;
return a-c;
}
bign operator/(const bign& a,const bign& b)
{
int i,len=a.len;
bign res,f;
for(i=len-; i>=; i--)
{
f=f*;
f.s[]=a.s[i];
while(f>=b)
{
f=f-b;
res.s[i]++;
}
}
while(res.s[len-]==&&len>)
len--;
res.len=len;
return res;
}
bign operator/(const bign& a,int& b)
{
bign c=b;
return a/c;
}
bign operator%(const bign& a,const bign& b)
{
int len=a.len;
bign f;
for(int i=len-; i>=; i--)
{
f=f*;
f.s[]=a.s[i];
while(f>=b)
f=f-b;
}
return f;
}
bign operator%(const bign& a,int& b)
{
bign c=b;
return a%c;
}
bign& operator+=(bign& a,const bign& b)
{
a=a+b;
return a;
}
bign& operator-=(bign& a,const bign& b)
{
a=a-b;
return a;
}
bign& operator*=(bign& a,const bign& b)
{
a=a*b;
return a;
}
bign& operator/=(bign& a,const bign& b)
{
a=a/b;
return a;
}
bign& operator++(bign& a)
{
a=a+;
return a;
}
bign& operator++(bign& a,int)
{
bign t=a;
a=a+;
return t;
}
bign& operator--(bign& a)
{
a=a-;
return a;
}
bign& operator--(bign& a,int)
{
bign t=a;
a=a-;
return t;
}
istream& operator>>(istream &in,bign& x)
{
string s;
in>>s;
x=s.c_str();
return in;
}
ostream& operator<<(ostream &out,const bign& x)
{
out<<x.str();
return out;
}
int main()
{
bign;
return ;
}
da shu mo ban的更多相关文章
- 【C#公共帮助类】 Utils 10年代码,最全的系统帮助类
为大家分享一下个人的一个Utils系统帮助类,可能有些现在有新的技术替代,自行修改哈~ 这个帮助类主要包含:对象转换处理 .分割字符串.截取字符串.删除最后结尾的一个逗号. 删除最后结尾的指定字符后的 ...
- 【C#公共帮助类】 Utils最全的系统帮助类
最近闲的没事做,自己想着做一些东西,不知不觉居然在博客园找到了这么多公共类,感觉还是挺有用的,平时自己还是用到了好多,就是缺少整理,现在为大家分享一下一个Utils系统帮助类,可能有些现在有新的技术替 ...
- C#字符操作
//字符串转ASCII码 // str1:字符串 str2:ASCII码 ] })[] == )//判断输入是否为字母 { str2= Encoding.GetEncoding(].ToString( ...
- 完整的系统帮助类Utils
//来源:http://www.cnblogs.com/yuangang/p/5477324.html using System; using System.Collections.Generic; ...
- C# 最全的系统帮助类
using System;using System.Collections;using System.Collections.Generic;using System.Configuration;us ...
- C#获取包括一二级汉字的拼音 首字母
C#获取包括一二级汉字的拼音 首字母 声母 汉字拼音转换 using System; using System.Collections.Generic; using System.Linq; usin ...
- Codeforces Round #384 (Div. 2) 解题报告
这场CF水题都非常的水,D题如果对树.DFS相关比较熟练的话也不难.比赛时前三题很快就过了,可是因为毕竟经验还是太少,D题就卡住了.比赛之后A题还因为没理解对题意fst了--(为什么这次就没人来hac ...
- Web前端-Vue.js必备框架(四)
Web前端-Vue.js必备框架(四) 计算属性: <div id="aaa"> {{ message.split('').reverse().join('') }} ...
- Day4:html和css
Day4:html和css 规范注意 链接里面不能再放链接. a里面可以放入块级元素. 空格规范 选择器与{之间必须包含空格. 如: .class {} 属性名与之后的:符号之间不允许包含空格, 而: ...
随机推荐
- 请问微信小程序let和var以及const有什么区别
在JavaScript中有三种声明变量的方式:var.let.const. var:声明全局变量,换句话理解就是,声明在for循环中的变量,跳出for循环同样可以使用. [JavaScript] 纯文 ...
- 将数组,矩阵存入csv文件中
我们在做各种模型训练时,往往会先将数据处理成矩阵,然后交给建模的人去训练.这时通常数据清洗者提交的是保存了矩阵的文件,一般为TXT或csv,接下来主要讲解我在实现这个过程中遇到的一些问题. impor ...
- Win10系列:JavaScript页面导航
页面导航是在开发应用的过程中使用频率较高的技术,其中比较常用的导航方式有多页导航和页内导航,采用多页导航方式的应用程序包含一系列的页面,在一个页面中加入另一个页面的链接地址后,单击链接将跳转到指定页面 ...
- asp.netmvc 三层搭建一个完整的项目
接下来用 asp.net mvc 三层搭建一个完整的项目: 架构图: 使用的数据库: 一张公司的员工信息表,测试数据 解决方案项目设计: 1.新建一个空白解决方案名称为Company 2.在该解决方案 ...
- day34 线程池 协程
今日内容: 1. 线程的其他方法 2.线程队列(重点) 3.线程池(重点) 4.协程 1.线程的其他方法 语法: Threading.current_thread() # 当前正在运行的线程对象的一个 ...
- JDK1.8源码逐字逐句带你理解LinkedHashMap底层
注意 我希望看这篇的文章的小伙伴如果没有了解过HashMap那么可以先看看我这篇文章:http://blog.csdn.net/u012403290/article/details/65442646, ...
- 《Python》进程之间的通信(IPC)、进程之间的数据共享、进程池
一.进程间通信---队列和管道(multiprocess.Queue.multiprocess.Pipe) 进程间通信:IPC(inter-Process Communication) 1.队列 概念 ...
- cv::ACCESS_MASK指定不明确的错误
今天想实现在opencv下使用模拟按键,结果出现cv::ACCESS_MASK指定不明确的错误,查找得到如下原因: 在winnt.h里面有一个cv的命名空间,同样定义了一个ACCESS_MASK,跟o ...
- Linux:Apache安装与启动
Apache安装与启动 1.查看是否安装:rpm -qa| grep httpd2.挂载系统 mount /dev/cdrom /mnt/cdrom3.进入软件包 cd /mnt/cdrom/Pack ...
- restful接口设计规范总结
这篇 文章主要是借鉴他人,但是自己很想总结出一套规范,以供向我这样的新手使用,用来规范代码,如果有什么好的提议,请不吝赐教,本篇文章长期更新! 一.重要概念: REST,即Representation ...