Cod sursa(job #906871)

Utilizator IonSebastianIon Sebastian IonSebastian Data 7 martie 2013 12:29:13
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int zero(int n){
    int rez=0,p=5;
    while(p<=n){
        rez+=n/p;
        n/=p;
    }
    return rez;
}
int caut(int p){
    int i=0,pas=1<<29;
    while(pas!=0){
        if(zero(i+pas)<p)
            i+=pas;
        pas/=2;
    }
    return i+1;
}
int main()
{
    int p,n;
    in>>p;
    n=caut(p);
    if(zero(n)==p)
        out<<n;
    else
        out<<"-1";
    return 0;
}