bitset高精 加减乘除。。。

bitset做高精度

#ifndef __MAX_INT__
#define __MAX_INT__
#ifndef __cplusplus
#warning When it isn't in c++ , it can so big .
typedef int bool
#define true 1
#define false 0
#define bitset<N>a bool a[N]
#endif // for C 
#include<bitset>
#include<cstdio>
#define itn int
#define abs(a) (a<0?~a-1:a)
#define isdigit(a) (a>=48&&a<=57)
#define isalpha(a) ((a>=65&&a<=90)||(a>=97&&a<=122))
#define qwq return 0;
#define qaq return 1;
//no

 namespace mystl{
	 using std::bitset;
	 using std::getchar;
	 using std::putchar;
	inline int read()
	{
		register bool f; register int x = 0; register char ch = getchar();
		while (ch < '0' || ch>'9') { if (ch == '-') f = false; ch = getchar(); }
		while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar(); }
		if (f)x = ~x - 1;
		return x;
	}
	inline void write(int a) {
		if(a>=10) write(a/10);
		putchar(a%10+'0');
	}
	inline void print(int& a) { if (a < 0)a = ~a - 1, putchar('-'); write(a); }
	template<const int MAXN>class solong {
	/*
		Name:__intMAXN   2.0
		Copyright:
		Author:Bill Liu
		Date: 02/09/22 15:23
		/\/\/\/\/\/\/\/\/\/\
		void in,out,*
	*/
		/*
		* 2022年11月6日16:00:54
		* __int n 
		* Bill Liu
		* 
		*/
		public:
			bitset<MAXN>a;
			bool zheng_;
			inline void operator=(solong aaa) {
				for(itn i=0;i<MAXN;i++) a[i]=aaa.a[i];
				zheng_=aaa.zheng_;
			}
			inline bool operator==(solong aaa) {
				if(zheng_!=aaa.zheng_) qwq
				for(int i=0;i<MAXN;i++) if(a[i]!=aaa.a[i]) qwq
				qaq
			}
			inline bool operator<(solong aaa) {
				if((*this)==aaa) return false;
				for(int i=0;i<MAXN;i++)
					if(a[i]>aaa.a[i]) qwq
					else if(a[i]<aaa.a[i]) qaq
			}
			inline void operator<<=(int aaa) {
				for(int i=MAXN;i>=aaa;i++) a[i]=a[i-aaa];
				for(int i=0;i<aaa;i++) a[i]=0;
			}
			inline void operator>>=(int aaa) {
				for(int i=0;i<MAXN-aaa;i++) a[i]=a[i+aaa];
				for(int i=MAXN-aaa;i<MAXN;i++) a[i]=0;
			}
			inline solong operator<<(int aaa) {
				solong t;
				t<<=aaa;
				return t;
			}
			inline solong operator>>(int aaa) {
				solong t;
				t>>=aaa;
				return t;
			}
			inline bool operator>=(solong aaa) {return (*this) < aaa  ? false : true ;}
			inline bool operator<=(solong aaa) {return (*this)==aaa || (*this)<aaa;}
			inline bool operator>(solong aaa) {return (*this) <= aaa  ? false : true ;}
			inline bool operator!=(solong aaa) {return (*this)==aaa ? false : true ;}
			inline void clear() {
				zheng_=true;
				for(int i=0;i<MAXN;i++) a[i]=false;
			}
			inline solong i_s(int t) {
				int i=0;
				solong tmp;
				tmp.clear();
				tmp.zheng_=i>=0;
				while(t) tmp.a[i++]=t&1;
				return tmp;
			}
			inline solong ll_s(long long t) {
				int i=0;
				solong tmp;
				tmp.clear();
				tmp.zheng_=i>=0;
				while(t) tmp.a[i++]=t&1;
				return tmp;
			}
			inline solong ull_s(unsigned long long t) {
				int i=0;
				solong tmp;
				tmp.clear();
				while(t) tmp.a[i++]=t&1;
				return tmp;
			}
			inline solong i128s(__int128 t) {
				int i=0;
				solong tmp;
				tmp.clear();
				tmp.zheng_=i>=0;
				while(t) tmp.a[i++]=t&1;
				return tmp;
			}
			inline solong operator+(solong aaa) {
				solong ret;
				ret.clear();
				ret.zheng_= aaa.zheng_ == zheng_ ;
				for(int i=0;i<MAXN;i++)
					if((a[i]&&(aaa.a[i] || ret.a[i])) || (aaa.a[i] && ret.a[i])) a[i] && aaa.a[i] && ret.a[i] ? ret.a[i+1]=ret.a[i]=true : ret.a[i+1]=true;
					else if(a[i] || aaa.a[i] || ret.a[i]) ret.a[i]=true;
				return ret;
			}
			inline solong operator-(solong aaa) {
				aaa.zheng_=!aaa.zheng_;
				return (*this)+aaa;
			}
			inline solong operator*(solong aaa) {
				solong ret=i_s(0),base=(*this);
				while(aaa!=i_s(0)) {
					if(aaa.a[0]) ret=ret+base;
					base<<=1;
					aaa>>=1;
				}
				return ret;
			}
			inline solong operator^(unsigned long long b) {
				solong ret=i_s(1);
				while(b) {
					if(b&1) ret=ret*(*this);
					solong t=(*this)*(*this);
					for(itn i=0;i<MAXN;i++) a[i]=t.a[i];
					zheng_=t.zheng_;
					b>>=2;
				}
				return ret;
			}
			inline solong operator/(solong aaa) {
				unsigned long long ii=0;
				solong aa=(*this);
				while(aa>=aaa) {
					solong t=aa-aaa;
					for(int i=0;i<MAXN;i++) aa.a[i]=t.a[i];
					aa.zheng_=t.zheng_;
					ii++;
				}
				if(aa!=aaa) ii--;
				return i_s(ii);
			}
			solong operator%(solong aaa) {
				solong t=(*this);
				return t-((t/aaa)*aaa);
			}
			inline void cpy(solong aaa) {
				for(int i=0;i<MAXN;i++) this->a[i]=aaa.a[i];
				this->zheng_=aaa.zheng_;
			}
			inline void operator%=(solong aaa) {cpy((*this)%aaa);}
			inline void operator/=(solong aaa) {cpy((*this)/aaa);}
			inline void operator*=(solong aaa) {cpy((*this)*aaa);}
			inline void operator-=(solong aaa) {cpy((*this)-aaa);}
			inline void operator+=(solong aaa) {cpy((*this)+aaa);}
			inline void operator^=(unsigned long long b) {cpy((*this)^b) ;}
			/*重载基本运算??*/
			inline solong operator~() {
				solong t=(*this);
				t.zheng_=!zheng_;
				for(int i=0;i<MAXN;i++) t.a[i]=t.a[i] ? false : true ;
				return t;
			}
			inline long long s_ll(solong aaa) {
				long long ret=0;
				for(int i=0;i<63;i++) if(a[i]) ret+=(1<<i);
				return ret;
			}
			inline void out() {
				solong t=(*this);
				if(t.zheng_==false) putchar('-');
				t.zheng_=true;
				if(t==i_s(0)) {
					putchar('0');
					return ;
				}
				do {
					char ch='0';
					ch+=(int) s_ll(t%i_s(10));
					putchar(ch);
					t/=i_s(10);
				} while(t!=i_s(0));
			}
			inline void in() {
				solong t;
				t.clear();
				string str;
				cin>>str;
				if(str[0]=='-') t.zheng_=false;
				while(str.size()) {
					if(str[0]=='-') str=str.substr(1,str.size());
					t=(t*i_s(10)+i_s(str[str.size()]-'0'));
					str=str.substr(0,str.size()-1);
				}
				cpy(t);
			}
	};
// 	class String{
// 		public:
// 			class Ch{
// 				public:
// 					bitset<6> value;
// 					inline int v() {
// 						int ret=0;
// 						if(value[0]) ret+=(1<<0);
// 						if(value[1]) ret+=(1<<1);
// 						if(value[2]) ret+=(1<<2);
// 						if(value[3]) ret+=(1<<3);
// 						if(value[4]) ret+=(1<<4);
// 						return ret;
// 					}
// 					inline char tch() {
// 						int tmp=v();
// 						if(tmp<26) return value[5] ? 'A'+tmp : 'a'+tmp ;
// 						else if(tmp<31) return value[5] ? (tmp-26)*2+1 : (tmp-26)*2 ;
// 						else return value[5] ? '\0' : '\n' ;
// 					}
// 					inline operator=(Ch o) {
// 						for(int i=0;i<6;i++) value[i]=o.value[i];
// 					}
// 					inline void f(int a) {
// 						for(int i=0;i<6;i++) value[i]=a&(1<<i);
// 					}
// 					inline operator()(char ch) {
// 						if(isalpha(ch)) f(ch>='a' ? ch-'a' : ch-'A'+32);
// 						else if(isdigit(ch)) f(ch&1 ? (ch-'0')/2+32 : (ch-'0')/2);
// 						else f(ch=='\n' ? 31 : 63);
// 					}
// 			};
// 			struct Char{
// 				Ch values;
// 				Char *next=NULL;
// 				Char *prev=NULL;
// 			};
// 			Char head,tail;
// 			int num;
// 			inline void clear() {
// 				head.next=&tail;
// 				head.prev=tail.next=NULL;
// 				tail.prev=&head;
// 				num=0;
// 			}
// 			inline void cpy_(Char *t,Char tm) {
// 			//	tm.
// 			}
// 			inline char operator[](int id) {
// 				if(num>=id) return '\0';
// 				Char tmp;
// //				for(int i=0;i<id;i++)
// 				return tmp.values.tch();
// 			}
// 			inline void operator+=(char a) {
// 				Char tmp;
// 				tmp.values.f(63);
// 				head.next=&tmp;
// 				tmp.prev=&head;
// 				tail.prev=&tmp;
// 				tmp.next=&tail;
// 				num++;
// 			}
// 			inline void pop_back() {
// 				num--;
				
// 			}
// 	};
	// class lick {
	// 	/*protected*/
	// 	private:
	// 		struct spot{
	// 			spot *prev;
	// 			spot *next;
	// 			spot *now_;
	// 			int value;
	// 		};
	// 		inline void cs(spot *t,spot &a) {
	// 			a.next=t->next;
	// 			a.now_=t->now_;
	// 			a.prev=t->prev;
	// 			a.value=t->value;
	// 		}
	// 	public :
	// 		spot h,t;
	// 		int num;
    //         inline void start() {
	// 		    h.next=t.now_;
	// 		    t.prev=h.now_;
	// 		    num=0;
    //         }
	// 		inline void operator+=(int v) {
	// 			spot tt;
	// 			tt.value=v;
	// 			spot *tmp=t.prev;
	// 			tt.prev=t.prev;
	// 			tmp->next=tt.now_;
	// 			t.prev=tt.now_;
	// 			tt.next=t.now_;
	// 			num++;
	// 		}
	// 		inline spot operator[](int id) {
	// 			spot tt=h;
	// 			for(int i=0;i<=id;i++) cs(tt.next,tt);
	// 			return tt;
	// 		}
	// };
// }
#endif

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值