Cod sursa(job #830305)

Utilizator RadulescuSerbanRadulescu Serban RadulescuSerban Data 6 decembrie 2012 16:59:20
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>

using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");

int p;

int zero(int x)
{
    int nr=0;
    while(x != 0)
    {
        nr += x / 5;
        x = x / 5;
    }
    return nr;
}

int cautb(int p)
{
    int i=0,pas=1<<29;
    while(pas != 0)
    {
        if(zero(i+pas) < p)
            i+=pas;
        pas/=2;
    }
    return i;
}

int main()
{
    int t,p;
    in >> p;
    t = cautb(p) + 1;
    if(zero(t) == p)
        out << t;
    else
        out << -1;
    return 0;
}