Pagini recente » Cod sursa (job #369720) | Cod sursa (job #2837662) | Cod sursa (job #930399) | Cod sursa (job #3261303) | Cod sursa (job #146710)
Cod sursa(job #146710)
#include <stdio.h>
#include <string.h>
int P[1000002],S[1000002],A[1000002],n,p;
void initializare ()
{
do P[++P[0]]=p%10; while (p/=10);
}
void produs ()
{
int i,j,t;
memset ( A , 0 , (2*P[0]+2)*sizeof ( int ) );
for ( i=1 ; i<=P[0] ; i++ )
{
for ( j=1,t=0 ; j<=P[0] ; j++ )
{
t+=P[i]*P[j]+A[i+j-1];
A[i+j-1]=t%10;
t/=10;
}
A[0]=i+j-2;
if (t) A[++A[0]]=t;
}
memcpy ( P , A , (A[0]+1)*sizeof ( int ) );
}
void suma ()
{
int i,j,t;
memset ( A , 0 , (S[0]+P[0]+2)*sizeof ( int ) );
for ( i=1 ; i<=P[0] ; i++ )
{
for ( j=1,t=0 ; j<=S[0] ; j++ )
{
t+=P[i]*S[j]+A[i+j-1];
A[i+j-1]=t%10;
t/=10;
}
A[0]=i+j-2;
if (t) A[++A[0]]=t;
}
memcpy ( S , A , (A[0]+1)*sizeof ( int ) );
}
int main ()
{
freopen ( "lgput.in" , "r" , stdin );
scanf ( "%d %d" , &p , &n );
fclose ( stdin );
int c; S[S[0]=1]=1;
for ( initializare() ; n ; n>>=1 )
{
for (c=P[0] ; c ; c-- ) printf( "%d" , P[c] );
printf ( "\n" );
if (n&1) suma ();
if ( n>>1) produs ();
}
// printf ( "a merse\n" );
freopen ( "lgput.out" , "w" , stdout );
while ( S[0] ) printf( "%d" ,S[S[0]--] );
printf ( "\n" );
fclose ( stdout );
return 0;
}