Cod sursa(job #1252102)

Utilizator grimmerFlorescu Luca grimmer Data 30 octombrie 2014 13:27:38
Problema Factorial Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
using namespace std;
long p;
int zero (int n)
{
    long rez;
    rez=0;
    while(n>=5)
    {
        rez+=n/5;
        n/=5;
    }
    return rez;
}
int main()
{
    int i=0;
    ifstream in("fact.in");
    ofstream out("fact.out");
    in>>p;
    in.close();
    int pas = 1<<24;
    while (pas!=0)
    {
        if(zero(pas+i)<p)
            i+=pas;
        pas>>=1;
    }
    if(zero(i+pas+1)==p)
        out<<i+1;
    else
        out<<-1;
    out.close();

    return 0;
}