Cod sursa(job #805437)

Utilizator teoionescuIonescu Teodor teoionescu Data 31 octombrie 2012 14:52:21
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int zero(int n){
    int nr=0;
    while(n>=5){
        nr+=n/5;
        n /= 5;
    }
    return nr;
}
int caut(int x){
    int i=0, pas = 1 <<30;
    while(pas!=0){
        if(zero(i+pas)<x) i+=pas;
        pas /=2;
    }
    return 1+i;
}
int main()
{
    int p,n;
    in>>p;
    n=caut(p);
    if(zero(n)==p) out<<n<<"\n";
    else out<<"-1\n";
    return 0;
}