Cod sursa(job #1697395)

Utilizator andrew_assassin789Andrei Manea andrew_assassin789 Data 1 mai 2016 21:35:39
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <algorithm>
using namespace std;
unsigned int cate0(unsigned int n)
{
    if (!n) return 1;
    unsigned int n5=0,i,x;
    for (i=5;i<=n;i+=5)
    {
        x=i;
        while (!(x%5))
            x/=5,n5++;
    }
    return n5;
}
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    unsigned int i,step,p,n;
    f>>p;n=5*p;
    for (step=1;step<=n;step<<=1);
    step>>=1;
    for (i=0;step;step>>=1)
    {
        if (cate0(i+step)<p)
            i+=step;
    }
    if (cate0(i+1)==p) g<<i+1<<'\n';
    else g<<"-1\n";
    f.close();
    g.close();
    return 0;
}