大整数

#include
#define re register
#define ll long long
#define RS(p) p<<1
#define LS(p) p<<1|1
#define MAX_N 105
#define INF 0x3f3f3f3f
#define MOD 1000007
#define Pii pair
using namespace std;

class BigInteger{
private:
	static const int BASE = 100000000;
	static const int WIDTH = 8;
	vector<long long> s;
public:
	BigInteger(long long num=0){*this=num;} //构造函数
	
	BigInteger operator = (long long num){  //赋值运算
		s.clear();
		do{
			s.push_back(num % BASE);
			num /= BASE;
		} while(num > 0);
		return *this;
	}
	
	BigInteger operator = (const string& str){
		s.clear();
		int x,len=(str.length()-1)/WIDTH+1;
		for(int i=0;i<len;i++){
			int end=str.length()-i*WIDTH;
			int start=max(0,end-WIDTH);
			sscanf(str.substr(start,end-start).c_str(),"%d",&x);
			s.push_back(x);
		}
		return *this;
	}
	
	friend ostream& operator << (ostream &out,const BigInteger& x){
		out<<x.s.back();
		for(int i=x.s.size()-2;i>=0;i--){
			char buf[20];
			sprintf(buf,"%08d",x.s[i]);
			for(int j=0;j<strlen(buf);j++) out<<buf[j];
		}
		return out;
	}
	
	friend istream& operator >> (istream &in,BigInteger& x){
		int s;
		if(!(in>>s)) return in;
		x=s;
		return in;
	}
	
	BigInteger operator + (const BigInteger& b) const{
		BigInteger c;
		c.s.clear();
		for(int i=0,g=0;;i++){
			if(g==0&&i>=s.size()&&i>=b.s.size()) break;
			int x=g;
			if(i<s.size()) x+=s[i];
			if(i<b.s.size()) x+=b.s[i];
			c.s.push_back(x%BASE);
			g=x/BASE;
		}
		return c;
	}
	
	BigInteger operator += (const BigInteger &b){
		*this=*this+b; return *this;
	}
	
	BigInteger operator * (const long long& b) const{
		BigInteger c;
		long long g=0;
		c.s.clear();
		for(int i=0; ; i++){
			if(g==0 && i>=s.size()) break;
			long long x=g;
			if(i<s.size()) x+=s[i]*b;
			c.s.push_back(x%BASE);
			g=x/BASE;
		}
		return c;
	}
	
	BigInteger operator / (const long long& b) const{
		BigInteger c, c1;
		long long g = 0;
		c.s.clear();
		for(int i=s.size()-1; i>=0; i--){
			g = g*BASE+s[i];
			c.s.push_back(g/b);
			g = g%b;
		}
		c1.s.clear();
		for(int i=c.s.size()-1; i >= 0; i--){
			c1.s.push_back(c.s[i]);
		}
		while(c1.s.back()==0 && c1.s.size()>1) c1.s.pop_back();
		return c1;
	}
	
	bool operator < (const BigInteger& b) const{
		if(s.size() != b.s.size()) return s.size()<b.s.size();
		for(int i = s.size()-1; i>= 0;i--)
			if(s[i] != b.s[i]) return s[i]<b.s[i];
		return false;           //相等
	}
	
	bool operator > (const BigInteger& b) const{return b<*this;}
	bool operator <= (const BigInteger& b) const{return !(b<*this);}
	bool operator >= (const BigInteger& b) const{return !(*this<b);}
	bool operator != (const BigInteger& b) const{return b<*this||*this<b;}
	bool operator == (const BigInteger& b) const{return !(b<*this)&&!(*this<b);}

};



/*void print(const BigInteger& x){
	printf("%lld",x.s.back());
	for(int i=x.s.size()-2;i>=0;i--){
		printf("%08lld",x.s[i]);
	}
}
*/
int main() {
	BigInteger a;
	long long b;
	cin >> a >> b;
	cout << a/b;
	return 0;
}


你可能感兴趣的:(世界第一可爱的我的算法学习之路)