#include <iostream>
#include <string.h>
#include <string>
#define DIGIT 4
#define DEPTH 10000
#define MAX 400 //数字的位数*4 ,这里就可以保存1600位数的整数
typedef int bigint_t[MAX + 1];
using namespace std;
char combuffer[MAX*DIGIT+10]; //通用buffer
inline int stob(bigint_t a, char * buf)
{
int i,j,sgn = 1;
memset(a,0,sizeof(bigint_t));
if(*buf == '-') sgn = -1 , buf++;
else if(*buf == '+') buf++;
for (a[0] = strlen(buf) , i = a[0]/2 -1 ; i >= 0 ; i--) std::swap(buf[a[0] - i -1],buf[i]); //交换
for (a[0] = (a[0] + DIGIT -1)/DIGIT , j= strlen(buf) ; j < DIGIT*a[0] ; buf[j++] = '0'); //补0
for (i = 1 ; i <= a[0] ; i++)
for( a[i] = 0 , j = 0 ; j < DIGIT ; j++)
a[i] = a[i]*10 + buf[i*DIGIT - 1 -j] - '0'; //4位存
for (;!a[a[0]] && a[0] > 1 ; a[0]--); //去零
if (a[0] == 1 && !a[1] ) sgn=0; //为0
return sgn;
}
void bigadd(bigint_t &a, const bigint_t b) // a = a + b
{
int i;
for (i = 1 ;i <= b[0] ; i++)
if ( (a[i] += b[i]) >= DEPTH)
a[i]-=DEPTH , a[i+1]++;
if (b[0] >= a[0])
a[0] = b[0];
else
for (;a[i] >= DEPTH && i < a[0] ; a[i] -= DEPTH, i++ ,a[i]++);
a[0] += ( a[a[0]+1] > 0);
}
void bigsub(bigint_t &a , const bigint_t b) // a = a - b
{
int i;
for (i = 1;i <= b[0] ; i ++)
if (( a[i] -= b[i] ) < 0)
a[i+1]--,a[i] += DEPTH;
for (;a[i] < 0;a[i] += DEPTH, i++ , a[i]--);
for (;!a[a[0]] && a[0] > 1 ; a[0]--);
}
void bigmul(bigint_t c,const bigint_t a,const bigint_t b){ // c = a*b
int i,j;
memset((void*)c,0,sizeof(bigint_t));
for (c[0] = a[0] + b[0] - 1 , i = 1 ; i <= a[0] ; i++)
for (j = 1 ; j <= b[0] ; j++)
if ( ( c[i+j-1] += a[i]*b[j] ) >= DEPTH)
c[i+j] += c[i+j-1] / DEPTH ,c[i+j-1]%=DEPTH;
for ( c[0] += (c[c[0]+1]>0) ; !c[c[0]]&&c[0]>1 ; c[0]--);
}
int cmp(const bigint_t a , const bigint_t b)
{
int i;
if (a[0]!=b[0])
return a[0]-b[0];
for (i=a[0];i;i--)
if (a[i]!=b[i])
return a[i]-b[i];
return 0;
}
/*
----------------------------除法部分,
*/
int cmp2(const bigint_t a,const int c,const int d,const bigint_t b){
int i , t = 0 , O = -DEPTH * 2;
if (b[0]-a[0]< d && c)
return 1;
for (i = b[0] ; i > d ; i--){
t = t * DEPTH + a[i-d] * c-b[i];
if (t > 0) return 1;
if (t < O) return 0;
}
for (i = d ; i ; i--){
t = t*DEPTH-b[i];
if (t > 0) return 1;
if (t < O) return 0;
}
return t > 0;
}
void sub2(bigint_t a,const bigint_t b,const int c,const int d){
int i,O = b[0] + d;
for (i = 1 + d ; i <= O ; i++)
if ((a[i] -= b[i-d]*c)<0)
a[i+1] += (a[i]-DEPTH+1)/DEPTH, a[i] -= (a[i]-DEPTH+1)/DEPTH*DEPTH;
for (;a[i] < 0 ; a[i+1] += (a[i]-DEPTH+1)/DEPTH , a[i] -= (a[i]-DEPTH+1)/DEPTH*DEPTH,i++);
for (;!a[a[0]] && a[0]>1 ;a[0]--);
}
void bigdiv(bigint_t c,bigint_t a,const bigint_t b){
int h , l , m ,i;
memset((void*)c,0,sizeof(bigint_t));
c[0] = (b[0]<a[0]+1) ? (a[0]-b[0]+2) :1;
for (i = c[0]; i ;sub2(a , b , c[i] = m, i-1) , i--)
for (h = DEPTH - 1 , l=0 , m = (h + l + 1)>>1 ; h > l ; m = (h + l + 1)>>1)
if (cmp2( b , m , i-1 , a)) h = m-1;
else l = m;
for (;!c[c[0]] && c[0] > 1 ; c[0]--);
c[0] = c[0]>1 ? c[0]:1;
}
//////////////////////////////////////////////////////////////////////////
struct bigint{
/*
如没有负数和减法,重载可以全部不用写
*/
bigint_t value;
int sgn;
bigint (char *buf) { //构造器
sprintf(combuffer,"%s",buf);
sgn = stob(value,combuffer);
}
bigint (int v) { //整型构造
sgn = stob(value,itoa(v,combuffer,10));
}
bigint (){
memset(value,0,sizeof(bigint_t));
sgn = 0;
}
void init(char *buf) //设定值,如不需要,可以不用写
{
sprintf(combuffer,"%s",buf);
sgn = stob(value,combuffer);
}
void init(int v) { sgn = stob(value,itoa(v,combuffer,10)); }
void show() //显示字符的函数
{
if(sgn == -1)
printf("-");
int i,j;
for (printf("%d",value[i=value[0]]),i--;i;i--)
for (j=DEPTH/10;j;j/=10)
printf("%d",value[i]/j%10);
}
inline bigint & operator = (const bigint& a)
{
memcpy(value,a.value,sizeof(bigint_t));
sgn = a.sgn;
return *this;
}
inline bigint& operator += (const bigint& a){
if(sgn == a.sgn) bigadd(value,a.value);
else if(sgn && a.sgn)
{
int ret=cmp(value,a.value);
if(ret > 0)
bigsub(value,a.value);
else if(ret < 0)
{
bigint_t t;
memcpy(t,value,sizeof(bigint_t));
memcpy(value,a.value,sizeof(bigint_t));
bigsub(value,t);sgn=a.sgn;
}
else memset(value,0,sizeof(bigint_t)),value[0]=1,sgn=0;
}else if(!sgn)
memcpy(value,a.value,sizeof(bigint_t)),sgn=a.sgn;
return *this;
}
inline bigint & operator + (const bigint & a)
{
bigint ret;
memcpy(ret.value,value,sizeof(bigint_t));
ret.sgn = sgn;
ret += a;
return ret;
}
inline bigint& operator -= (const bigint& a){
if(sgn * a.sgn < 0)bigadd(value,a.value);
else if(sgn && a.sgn)
{
int ret = cmp(value,a.value);
if(ret > 0) bigsub(value,a.value);
else if( ret < 0)
{
bigint_t t;
memcpy(t,value,sizeof(bigint_t));
memcpy(value,a.value,sizeof(bigint_t));
bigsub(value,t);sgn =- sgn;
}else memset(value,0,sizeof(bigint_t)),value[0]=1,sgn=0;
}
else if(!sgn)
bigadd(value,a.value),sgn=-a.sgn;
return *this;
}
inline bigint & operator - (const bigint &a)
{
bigint ret;
memcpy(ret.value,value,sizeof(bigint_t));
ret.sgn = sgn;
ret -= a;
return ret;
}
inline bigint & operator * (const bigint &a)
{
bigint ret;
bigmul(ret.value,value,a.value);
ret.sgn = sgn*a.sgn;
return ret;
}
//除法重载
inline bigint& operator/=(const bigint& a)
{
bigint_t t;
bigdiv(t, value , a.value);
memcpy(value,t,sizeof(bigint_t));
sgn=(value[0]==1&&!value[1])?0:sgn*a.sgn;
return *this;
}
inline bigint operator / (const bigint& a){
bigint ret;
bigint_t t;
memcpy(t,value,sizeof(bigint_t));
bigdiv(ret.value,t,a.value);ret.sgn=(ret.value[0]==1&&!ret.value[1])?0:sgn*a.sgn;
return ret;
}
};
int main()
{
bigint a(0),b("1"),c;
scanf("%s",combuffer);
c.sgn = stob(c.value,combuffer);
a.init(5);
b.init("111111111111111111111111111111111111111111111111111111111111111111111111111");
c.show(),puts("");
c = a+b;
c.show(),puts("");
c = a*c;
c.show(),puts("");
c = c/a;
c.show(),puts("");
return 0;
}