Pagini recente » Cod sursa (job #2004482) | Cod sursa (job #1603838) | Cod sursa (job #1055461) | Cod sursa (job #398424) | Cod sursa (job #73053)
Cod sursa(job #73053)
Utilizator |
|
Data |
16 iulie 2007 15:16:59 |
Problema |
Numere 2 |
Scor |
75 |
Compilator |
cpp |
Status |
done |
Runda |
Arhiva de probleme |
Marime |
1.64 kb |
//50 puncte
#include <cstdio>
#include <string.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
#define FIN "numere2.in"
#define FOUT "numere2.out"
#define dmax 200
struct bignum
{
int n;
int x[dmax];
};
bignum P,A;
int B;
int i,j;
void read_data()
{
int i=1;
char c[10];
while (!feof(stdin))
{
scanf("%c",&c[0]);
P.x[i]=atoi(c);
i++;
}
P.n=i-3; P.x[i-1]=0;
int aux;
for (i=1; i<=P.n/2; i++)
{ aux=P.x[i]; P.x[i]=P.x[P.n-i+1]; P.x[P.n-i+1]=aux; }
}
void convert (bignum &A, int x)
{
int i=0,c;
memset(A.x,0,sizeof(A.x));
while (x)
{
c=x % 10;
A.x[++i]=c;
x/=10;
}
A.n=i;
}
void multint(bignum &A, int x)
{
int i,t=0;
for (i=1; i<=A.n; i++)
{ A.x[i]=(t+=(A.x[i]*x))%10; t/=10;}
while (t>0) {A.x[++A.n]=t%10; t/=10; }
}
int main()
{
freopen(FIN,"r",stdin);
freopen(FOUT,"w",stdout);
read_data();
for (i=2; i<=1000; i++)
{
convert(A,i);
if (memcmp(A.x,P.x,sizeof(A.x))==0)
{
printf("%d\n%d\n",i,1);
return 0;
}
for (j=2; j<=400; j++)
{
multint(A,i);
if (A.n==P.n)
if (memcmp(A.x,P.x,sizeof(P.x))==0) break;
if (A.n>P.n) break;
}
if (memcmp(A.x,P.x,sizeof(A.x))==0)
{
printf("%d\n%d\n",i,j);
return 0;
}
}
return 0;
}