Cod sursa(job #2203464)

Utilizator DordeDorde Matei Dorde Data 12 mai 2018 14:05:02
Problema Factorial Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#define i64 long long
using namespace std;
char const in [] = "fact.in";
char const out [] = "fact.out";
ifstream f (in);
ofstream g (out);
int p;
int lastzero (int val)
{
    int power = 5 , searched = 0;
    while(val / power)
    {
        searched += val / power;
        power *= 5;
    }
    return searched;
}
int main()
{
    f >> p;
    unsigned i64 from , to , number , found;
    from = 1 , to = 1e17 * 8;
    while(from <= to)
    {
        i64 mid = (from + to) / 2;
        number = lastzero (mid);
        if(number >= p)
            found = mid , to = mid - 1;
        else
            from = mid + 1;
    }
    g << found << '\n';
    return 0;
}