Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- const int ksize = 1000;
- class Huge{
- public:
- int a[ksize];
- void Reset(){
- memset(a,0,sizeof(a));
- a[0]=1;
- }
- Huge(){
- Reset();
- }
- void setValue(int x){
- Reset();
- a[0]=0;
- do{
- a[0]++;
- a[a[0]] = x % 10;
- x/=10;
- }while(x);
- }
- void operator +=(const Huge &other){
- int i, t= 0;
- for(i = 1; i <= a[0] || i <= other.a[0] || t != 0;i++, t/=10)
- {
- a[i] = (t+= a[i] + other.a[i]) % 10;
- }
- a[0] = i - 1;
- }
- void operator -=(const Huge &other){
- int i, t =0;
- for(i=1;i<= a[0];i++)
- {
- a[i] = (a[i] - t) - other.a[i];
- if(a[i] < 0)
- t = 1;
- else
- t = 0;
- a[i] += t * 10;
- }
- while(a[0] > 1 && (a[a[0]] == 0))
- a[0]--;
- }
- void operator *=(const int x){
- int i, t = 0;
- for(i = 1; i <= a[0]; i++, t/=10)
- {
- a[i] = (t+= a[i] * x) % 10;
- }
- a[0] = i -1;
- while(t)
- {
- a[++a[0]] = t % 10;
- t/=10;
- }
- }
- void operator *=(const Huge &other)
- {
- int i,j,t=0;
- Huge aux;
- for(i=1; i<=a[0] ; i++)
- for(j = 1, t = 0; j <= other.a[0] || t ; j++, t/=10)
- aux.a[i+j-1] = (t += aux.a[i+j-1] + a[i] * other.a[j]) % 10;
- if(i + j - 3 > aux.a[0])
- aux.a[0] = i + j - 3;
- Reset();
- for(i = 1; i<= aux.a[0]; i++)
- a[i] = aux.a[i];
- a[0] = aux.a[0];
- }
- void addInteger(int x)
- {
- int i, t= 0;
- for(i = 1; i<= a[0] || x!=0 || t!= 0; i++, t/=10, x/=10)
- {
- a[i] = (t += a[i] + x % 10) % 10;
- }
- a[0] = i - 1;
- }
- void printNumber()
- {
- int i;
- for(i = a[0]; i >= 1; i--)
- printf("%d",a[i]);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement