Mai intai trebuie sa te autentifici.

Cod sursa(job #1772945)

Utilizator woogiefanBogdan Stanciu woogiefan Data 7 octombrie 2016 11:57:15
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("factorial.in");
ofstream fout("factorial.out");


long p , i , step;

long power(int n){
    long pow = 5 , t = 0;

    while ( pow <= n )
    {
        t += n / pow;
        pow *= 5;
    }

    return t;
}

int main()
{
    fin >> p;
    step = 1<<30;
    while(step != 0){
        if(power(i + step) < p)
            i += step;
        step /= 2;
    }
    i++;

    if(power(i) == p) fout << i;
    else fout << "-1";

    return 0;
}