Cod sursa(job #1384868)

Utilizator apostolandreiApostol Andrei Laurentiu apostolandrei Data 11 martie 2015 14:51:05
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 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 fc(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 f("fact.in");
    ofstream g("fact.out");
    f>>p;
    g<<fc(p);


    return 0;
}