Cod sursa(job #1384865)

Utilizator danalexandruDan Alexandru danalexandru Data 11 martie 2015 14:50:08
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <iostream>
#include <fstream>
using namespace std;

int zero(int n)
{
    int x=0;
    while(n>=5)
    {
        x+=n/5;
        n/=5;
    }
    return x;
}

long long search(int p)
{
    long long i=0;
    int pas=1<<30;
    while(pas!=0)
    {
        if(zero(i+pas)<p)
            i+=pas;
        pas/=2;
    }

    if(zero(i+1)==p)
        return i+1;
    return -1;
}

int main()
{
    int p;
    ifstream in("fact.in");
    ofstream out("fact.out");
    in>>p;
    out<<search(p);
    return 0;
}