#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的更多相关文章

  1. 【C#公共帮助类】 Utils 10年代码,最全的系统帮助类

    为大家分享一下个人的一个Utils系统帮助类,可能有些现在有新的技术替代,自行修改哈~ 这个帮助类主要包含:对象转换处理 .分割字符串.截取字符串.删除最后结尾的一个逗号. 删除最后结尾的指定字符后的 ...

  2. 【C#公共帮助类】 Utils最全的系统帮助类

    最近闲的没事做,自己想着做一些东西,不知不觉居然在博客园找到了这么多公共类,感觉还是挺有用的,平时自己还是用到了好多,就是缺少整理,现在为大家分享一下一个Utils系统帮助类,可能有些现在有新的技术替 ...

  3. C#字符操作

    //字符串转ASCII码 // str1:字符串 str2:ASCII码 ] })[] == )//判断输入是否为字母 { str2= Encoding.GetEncoding(].ToString( ...

  4. 完整的系统帮助类Utils

    //来源:http://www.cnblogs.com/yuangang/p/5477324.html using System; using System.Collections.Generic; ...

  5. C# 最全的系统帮助类

    using System;using System.Collections;using System.Collections.Generic;using System.Configuration;us ...

  6. C#获取包括一二级汉字的拼音 首字母

    C#获取包括一二级汉字的拼音 首字母 声母 汉字拼音转换 using System; using System.Collections.Generic; using System.Linq; usin ...

  7. Codeforces Round #384 (Div. 2) 解题报告

    这场CF水题都非常的水,D题如果对树.DFS相关比较熟练的话也不难.比赛时前三题很快就过了,可是因为毕竟经验还是太少,D题就卡住了.比赛之后A题还因为没理解对题意fst了--(为什么这次就没人来hac ...

  8. Web前端-Vue.js必备框架(四)

    Web前端-Vue.js必备框架(四) 计算属性: <div id="aaa"> {{ message.split('').reverse().join('') }} ...

  9. Day4:html和css

    Day4:html和css 规范注意 链接里面不能再放链接. a里面可以放入块级元素. 空格规范 选择器与{之间必须包含空格. 如: .class {} 属性名与之后的:符号之间不允许包含空格, 而: ...

随机推荐

  1. Win10系列:JavaScript获取文件和文件夹列表

    在应用程序中有时可能需要获取用户库中的内容,以便执行相关的操作.如果要获取某个用户库中的内容,需要先获取到这个用户库,获得用户库可以通过Windows.Storage命名空间中的KnownFolder ...

  2. UVa 10859 - Placing Lampposts 树形DP 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. what’s this?

    jdk,jre,jvm三者区别:JDK: (Java Development ToolKit) java开发工具包.JDK是整个java的核心! 包括了java运行环境 JRE(Java Runtim ...

  4. mysql数据库存储引擎及区别

    MySQL有多种存储引擎,每种存储引擎有各自的优缺点,可以择优选择使用:MyISAM.InnoDB.MERGE.MEMORY(HEAP).BDB(BerkeleyDB).EXAMPLE.FEDERAT ...

  5. jdk8-四大函数式接口

    jdk8四大核心接口 1.Comsumer接口 2.Function函数型接口 3.断言型接口 4.供给型接口 核心接口的子接口

  6. core net 实现post 跟get

    using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using Syst ...

  7. Calendar获取当前年份、月份、日期

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Te ...

  8. python基础练习。

    1,简单输入输出交互 输入姓名 name=input('请输入姓名:') 输入学号 number=input('请输入您的学号:') 输出姓名和学号 print('请确认您的姓名和学号:'name,n ...

  9. struts请求参数注入的三种方式

    .请求参数的注入 在Struts2框架中,表单的提交的数据会自动注入到与Action对象相对应的属性.它与Spring框架中的IoC的注入原理相同,通过Action对象为属性提供setter方法注入 ...

  10. 201621123001 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 关于泛型 <T extends Comparable <T ...