Cod sursa(job #1384831)

Utilizator AndreiMedarMedar Andrei AndreiMedar Data 11 martie 2015 14:32:51
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.39 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<<15;
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;
}