Mai intai trebuie sa te autentifici.

Cod sursa(job #561963)

Utilizator cernat.catallinFMI Cernat Catalin Stefan cernat.catallin Data 22 martie 2011 01:20:36
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
using namespace std;
int numarzerouri(unsigned long long  n)
{   int fact=0;
    while(n) {fact+=n/5; n/=5;}
    return fact;
}
int main()
{
    ifstream f ("fact.in");
    ofstream g ("fact.out");
    unsigned long long n,a,b,p;
    bool gasit=false;
    f>>p;
    f.close();
    if(p==0) g<<1;
    else
    {
        a=1;
        b=100000001;
        while(a<=b && !gasit)
        {
            n=(a+b)/2;
            if(numarzerouri(n)==p) gasit=true;
            else if(numarzerouri(n)>p) b=n-1;
            else a=n+1;
        }
        if(gasit==true)
        {
            while(n%5!=0) n--;
            g<<n;
        }
        else g<<-1;
    }
}