Cod sursa(job #29051)

Utilizator mihai0110Bivol Mihai mihai0110 Data 8 martie 2007 15:55:43
Problema Numere 2 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<fstream.h>
#include<math.h>
ifstream f("numere2.in");
ofstream g("numere2.out");
long a,b,d,j,p,n,x,y,i,fct[100],put[100];
int main()
{
f>>p;
n=0;
for(d=2;d<=sqrt(p);d++)
if(p%d==0)
{
n++;
fct[n]=d;
while(p%d==0)
{
put[n]++;
p=p/d;
}
}
if(p!=1)
{
g<<p<<'\n';
g<<"1"<<'\n';
}
else
if(n==1)
{
g<<fct[1]<<'\n';
g<<put[1]<<'\n';
}
else
{
x=put[1];
y=put[2];
while(x!=y)
if(x>y)
x=x-y;
else
y=y-x;
for(i=3;i<n;i++)
{
y=put[i];
while(x!=y)
if(x>y)
x=x-y;
else
y=y-x;
}
a=1;
for(i=1;i<=n;i++)
for(j=1;j<=put[i]/x;j++)
a=a*fct[i];
b=x;
g<<a<<'\n';
g<<b<<'\n';
}
f.close();
g.close();
return 0;
}