Pagini recente » Cod sursa (job #2367971) | Cod sursa (job #771637) | Cod sursa (job #2227456) | Cod sursa (job #2967444) | Cod sursa (job #1236897)
#include <cstdio>
#include <cstring>
using namespace std;
char s[1000005];
bool rasp;
class HUGE {
private:
int x[1000001];
public:
HUGE() {
memset(x,0,sizeof(x));
x[0]=1;
}
HUGE(bool sss) {
gets(s);
int nn;
x[0]=strlen(s);
nn=x[0]-1;
for(int i=1; i<=x[0]; ++i) {
x[i]=s[nn]-'0';
--nn;
}
}
HUGE(const HUGE& other) {
memcpy(x,other.x,sizeof(other.x));
}
HUGE (long long n) {
memset(x,0,sizeof(x));
x[0]=0;
do {
x[++x[0]]=1LL*n%10;
n=1LL*n/10;
} while(n);
}
int cmp(const HUGE& other) {
if(x[0]<other.x[0]) return -1;
else if(x[0]>other.x[0]) return 1;
for(int i=x[0]; i>=0; --i)
if(x[i]<other.x[i]) return -1;
else if(x[i]>other.x[i]) return 1;
return 0;
}
void print() {
for(int i=x[0]; i>=1; --i) printf("%d",x[i]);
printf("\n");
}
HUGE operator *(const HUGE& other);
HUGE operator /=(long long kk);
bool operator ==(const HUGE& other);
HUGE operator +(int po);
};
HUGE HUGE::operator *(const HUGE& other) {
HUGE c;
c.x[0]=x[0]+other.x[0]-1;
int i,j,t;
for(i=1; i<=x[0]; ++i)
for(j=1; j<=other.x[0]; ++j)
c.x[i+j-1]+=x[i]*other.x[j];
t=0;
for(i=1; i<=c.x[0]; ++i) {
t=t+c.x[i];
c.x[i]=t%10;
t/=10;
}
int l=c.x[0];
while(t) {
++l;
c.x[l]=t%10;
t/=10;
}
c.x[0]=l;
return c;
}
HUGE HUGE::operator /=(long long kk) {
int r=0,i;
for(i=x[0]; i>0; --i) {
r=r*10+x[i];
x[i]=1LL*r/kk;
r=1LL*r%kk;
}
while(x[0]>1&&!x[x[0]]) --x[0];
rasp=r;
return *this;
}
inline bool HUGE:: operator ==(const HUGE& other) {
if((*this).cmp(other)!=0)
return 0;
return 1;
}
HUGE HUGE:: operator +(int po) {
x[1]++;
for(int i=1; i<=x[0]; ++i) {
if(x[i]>10) {
x[i+1]++;
x[i]-=10;
}
}
if(x[x[0]+1]==1) {
x[0]++;
}
return *this;
}
int main() {
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
long long k;
int po;
po=1;
bool sss;
HUGE A(sss);
scanf("%lld",&k);
HUGE Q(k);
A/=k;
if(!rasp) {
A=A*Q;
A.print();
} else {
A=A+po;
A=A*Q;
A.print();
}
return 0;
}