Cod sursa(job #1907065)

Utilizator matystroiaStroia Matei matystroia Data 6 martie 2017 17:39:08
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
using namespace std;

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

int p;

int main()
{
    fin>>p;

    int p2=0, p5=0;
    for(int n=1;;++n)
    {
        int aux=n;
        while(!(aux%2))p2++, aux/=2;
        while(!(aux%5))p5++, aux/=5;

        int zeroes=min(p2, p5);

        //fout<<n<<" "<<zeroes<<'\n';

        if(zeroes==p)
        {
            fout<<n;
            return 0;
        }
        else if(zeroes>p)
        {
            fout<<-1;
            return 0;
        }
    }
    return 0;
}