HISKrrr的板子库

高精度
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define ll long long
const int maxn = 1e4 + 10;
const int maxm = 1e4 + 10;
const int mod = 1e9 + 7;

struct node{
	ll a[maxn<<1];
	int len;
	node () {len = 0; memset(a,0,sizeof(a));}
	friend node operator +(node A,node B) {
		node C;
		if(A.a[0] && !B.a[0]) {A.a[0] = 0; return B - A;}
		if(!A.a[0] && B.a[0]) {B.a[0] = 0; return A - B;}
		if(A.a[0] && B.a[0]) C.a[0] = 1;
		for(rint i = 1;i <= max(A.len,B.len);++i) C.a[i] = A.a[i] + B.a[i];
		for(rint i = 1;i <= max(A.len,B.len);++i) C.a[i] += C.a[i-1] / mod,C.a[i-1] %= mod;
		C.len = max(A.len,B.len);
		while(C.a[C.len+1]) C.len++;
		return C;
	}
	friend node operator -(node A,node B) {
		node C;
		if(A.a[0] && !B.a[0]) {B.a[0] = 1; return A + B;}
		if(!A.a[0] && B.a[0]) {B.a[0] = 0; return A + B;}
		if(A.a[0] && B.a[0]) {B.a[0] = 0; return A + B;}
		if(A < B) {C = B - A,C.a[0] = 1; return C;}
		C.len = 0;
		for(rint i = max(A.len,B.len);i >= 1;--i) C.a[i] = A.a[i] - B.a[i];
		for(rint i = 1;i <= max(A.len,B.len);++i) if(C.a[i] < 0) C.a[i] += mod,C.a[i+1]--;
		for(rint i = max(A.len,B.len);i >= 1;--i) if(C.a[i]) {C.len = i; break;}
		return C;
	}
	friend node operator *(node A,node B) {
		node C; C.len = A.len + B.len - 1;
		if(A.a[0] ^ B.a[0]) C.a[0] = 1;
		for(rint i = 1;i <= A.len;++i) {
			for(rint j = 1;j <= B.len;++j) {
				C.a[i+j-1] += A.a[i] * B.a[j];
				C.a[i+j] += C.a[i+j-1] / mod;
				C.a[i+j-1] %= mod;
			}
		}
		while(C.a[C.len+1]) C.len++;
		return C;
	}
	friend node operator /(node A,int B) {
		node C;
		node D; D.push(B);
		if(A < D) return C;
		C = A;
		rint flag = B < 0;
		if(A.a[0] ^ flag) C.a[0] = 1;
		else C.a[0] = 0;
		for(rint i = A.len;i >= 1;--i) {
			if(i != 1) C.a[i-1] += A.a[i] % B * mod;
			C.a[i] /= B;
		}
		while(!C.a[C.len]) C.len--;
		return C;
	}
	friend node operator +(node A,int B) {
		A.a[1] += B;
		for(rint i = 2;i <= A.len;++i) A.a[i] += A.a[i-1] / mod,A.a[i-1] %= mod;
                while(A.a[A.len+1]) A.len++;
		return A;
	}
	friend bool operator !(node A) {
		for(rint i = 1;i <= A.len;++i) if(A.a[i]) return 0;
		return 1;
	}
	friend bool operator >(node A,node B) {
		rint flag = 0;
		if(A.a[0] && !B.a[0]) return 0;
		if(!A.a[0] && B.a[0]) return 1;
		if(A.a[0] && B.a[0]) flag = 1;
		if(A.len > B.len) return flag ? 0 : 1;
		if(A.len < B.len) return flag ? 1 : 0;
		for(rint i = A.len;i >= 1;--i) if(A.a[i] > B.a[i]) return flag ? 0 : 1; else if(A.a[i] < B.a[i]) return flag ? 1 : 0;
		return 0;
	}
	friend bool operator <(node A,node B) {
		rint flag = 0;
		if(A.a[0] && !B.a[0]) return 1;
		if(!A.a[0] && B.a[0]) return 0;
		if(A.a[0] && B.a[0]) flag = 1;
		if(A.len > B.len) return flag ? 1 : 0;
		if(A.len < B.len) return flag ? 0 : 1;
		for(rint i = A.len;i >= 1;--i) if(A.a[i] < B.a[i]) return flag ? 0 : 1; else if(A.a[i] > B.a[i]) return flag ? 1 : 0;
		return 0;
	}
	friend bool operator ==(node A,node B) {
		if(A.len ^ B.len) return 0;
		for(rint i = 0;i <= A.len;++i) if(A.a[i] != B.a[i]) return 0;
		return 1;
	}
	friend bool operator >=(node A,node B) {
		rint flag = 0;
		if(A.a[0] && !B.a[0]) return 0;
		if(!A.a[0] && B.a[0]) return 1;
		if(A.a[0] && B.a[0]) flag = 1;
		if(A.len > B.len) return flag ? 0 : 1;
		if(A.len < B.len) return flag ? 1 : 0;
		for(rint i = A.len;i >= 1;--i) if(A.a[i] > B.a[i]) return flag ? 0 : 1; else if(A.a[i] < B.a[i]) return flag ? 1 : 0;
		return 1;
	}
	friend bool operator <=(node A,node B) {
		rint flag = 0;
		if(A.a[0] && !B.a[0]) return 1;
		if(!A.a[0] && B.a[0]) return 0;
		if(A.a[0] && B.a[0]) flag = 1;
		if(A.len > B.len) return flag ? 1 : 0;
		if(A.len < B.len) return flag ? 0 : 1;
		for(rint i = A.len;i >= 1;--i) if(A.a[i] < B.a[i]) return flag ? 0 : 1; else if(A.a[i] > B.a[i]) return flag ? 1 : 0;
		return 1;
	}
	void read() {
		char s[maxm] = {}; scanf("%s",s+1);
		rint lenth = strlen(s+1);
		for(rint i = lenth;i >= 1;i -= 8) {
			++len;
			for(rint j = min(8,i);j >= 1;--j) a[len] = a[len] * 10 + s[i-j+1] - '0';
		}
	}
	void print () {
		if(a[0]) printf("-");
		printf("%lld",a[len]);
		for(rint i = len - 1;i >= 1;--i) printf("%.8lld",a[i]);
	}
	void push (int x) {//低精赋值给高精
		char s[maxm] = {};
		rint cnt = 0;
		while(x) {
			s[++cnt] = x%10 + '0';
			x /= 10;
		}
		reverse(s+1,s+cnt+1);
		for(rint i = cnt;i >= 1;i -= 8) {
			++len;
			for(rint j = min(8,i);j >= 1;--j) a[len] = a[len] * 10 + s[i-j+1] - '0';
		}
	}
	void clear () {memset(a,0,sizeof(a)); len = 0;}
};

int main(){
	
	return 0;
}

高精度(非压位

#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define ll long long
const int maxn = 150;
char s[maxn];
int limit[maxn];
int t[maxn];
int pos,len;

struct node{
	int a[320];
	node(){memset(a,0,sizeof(a));}
	friend node operator *(node A,node B) {
		node C;
		for(rint i = 1;i <= 300;++i) {
			for(rint j = 1;j <= 300;++j) {
				C.a[i+j-1] += A.a[i] * B.a[j];
				C.a[i+j] += C.a[i+j-1] / 10;
				C.a[i+j-1] %= 10;
			}
		}
		for(rint i = 1;i <= 300;++i) C.a[i+1] += C.a[i] / 10,C.a[i] %= 10;
		return C;
	}
	friend node operator *(node A,int B) {
		node C;
		for(rint i = 1;i <= 300;++i) C.a[i] = A.a[i]*B;
		for(rint i = 1;i <= 300;++i) C.a[i+1] += C.a[i] / 10,C.a[i] %= 10;
		return C;
	}
	friend node operator +(node A,node B) {
		node C;
		for(rint i = 1;i <= 300;++i) C.a[i] = A.a[i] + B.a[i];
		for(rint i = 1;i <= 300;++i) C.a[i+1] += C.a[i] / 10,C.a[i] %= 10;
		return C;
	}
	friend node operator +(node A,int B) {
		node C = A;
		C.a[1] += B;
		for(rint i = 1;i <= 300;++i) C.a[i+1] += C.a[i] / 10,C.a[i] %= 10;
		return C;
	}
	friend node operator -(node A,node B) {
		node C;
		for(rint i = 1;i <= 300;++i) C.a[i] = A.a[i] - B.a[i];
		for(rint i = 1;i <= 300;++i) if(C.a[i] < 0) C.a[i] += 10,C.a[i+1]--;
		return C;
	}
	friend bool operator <(node A,node B) {
		for(rint i = 300;i >= 1;--i) {
			if(A.a[i] < B.a[i]) return 1;
			else if(A.a[i] > B.a[i]) return 0;
		}
		return 0;
	}
	friend bool operator ==(node A,node B) {
		for(rint i = 300;i >= 1;--i) if(A.a[i] != B.a[i]) return 0;
		return 1;
	}
	friend bool operator >(node A,node B) {
		for(rint i = 300;i >= 1;--i) {
			if(A.a[i] > B.a[i]) return 1;
			else if(A.a[i] < B.a[i]) return 0;
		}
		return 0;
	}
	friend bool operator !=(node A,int B) {
		return A.a[1] != B;
	}
	void print(){
		rint pos = 0;
		for(rint i = 300;i >= 1;--i) if(a[i] != 0) {pos = i;break;}
		for(rint i = pos;i >= 1;--i) printf("%d",a[i]);
		if(!pos) printf("0");
	}
	void clear() {memset(a,0,sizeof(a));}
	void asas() {a[1] = -1;}
};

int main(){
	
	return 0;
}

posted @ 2020-11-29 21:19  HISKrrr  阅读(128)  评论(1编辑  收藏  举报