Cod sursa(job #1315230)

Utilizator GhermanGherman Stefan Gherman Data 12 ianuarie 2015 17:10:00
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;
int n,p;
int zero(int n)
{
    int nr=0;
    while(n>=5)
        nr+=(n/=5);
    return nr;
}
int cautbin()
{
    int i,pas;
    pas=1<<30;
    while(pas!=0)
    {
        if(zero(i+pas)<p)
            i+=pas;
        pas/=2;
    }
    return i+1;
}
int main()
{
    ifstream in("fact.in");
    in>>p;
    in.close();
    ofstream out("fact.out");
    n = cautbin();
    if (zero(n) == p)
        out << n;
    else
        out << -1;
    out.close();
    return 0;
}