Cod sursa(job #1234150)

Utilizator AndreiIstetulAndrei Andrei AndreiIstetul Data 26 septembrie 2014 20:03:14
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <climits>
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

int main()
{
    unsigned p, i, p2, p5, x, mn;
    bool ok;
    f >> p;
    p2 = p5 = 0;
    i = 2;
    while(!ok)
    {
        mn = i;
        x = i;
        while(x%2==0)
        {
            x/=2;
            ++p2;
        }
        while(x%5==0)
        {
            x/=5;
            ++p5;
        }
        if(min(p2,p5)==p) ok = 1;
        ++i;
    }
    g << mn;
    f.close();
    g.close();
    return 0;
}
/*ifstream f("fact.in");
ofstream f2("fact.out");

int main()
{
    long long p,f,ok,d,p2,p3,min,i;
    f>>p;
    f=1;
    ok=0;
    for(i=1;f<=LONG_LONG_MAX && ok==1;i++)
       {
        f=f*i;
        d=2;
        p2=p3=0;
        while(f%d==0)
        {
            f=f/d;
            p2++;
        }
        d=3;
        while(f%d==0)
        {
            f=f/d;
            p3++;
        }
        min=p2;
        if(min>p3) min=p3;
        if(min==p) ok=1;
       }
    if(ok==1) f2<<i;
    else f2<<"-1";
}
*/