Cod sursa(job #1246681)

Utilizator Darius15Darius Pop Darius15 Data 21 octombrie 2014 15:32:24
Problema Numere 2 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream f("numere2.in");
ofstream g("numere2.out");
struct poz{int val,baza,exp;};
int p,best,st,dr,m,i,x,j,putere;
long long pr;
poz v[90000];
bool cmp(poz a,poz b)
{
    if (a.val==b.val) return a.baza<b.baza;
    return a.val<b.val;
}

int main()
{
    f>>p;
    v[1].val=1;
    v[1].baza=1;
    v[1].exp=1;
    best=1;
    x=sqrt(p);
    for (i=2;i<=x;i++)
    {
        pr=1;
        for (j=1;j<=30;j++)
        {pr=pr*i;if (pr>p) j=31;
          else v[++best].val=pr,v[best].baza=i,v[best].exp=j;
        }
    }
    sort(v+1,v+best+1,cmp);
    for (i=1;i<=best;i++)
        if (p==v[i].val) g<<v[i].baza<<'\n'<<v[i].exp,i=best+2;
    if (i==best+1) g<<p<<'\n'<<1;
    return 0;
}