Cod sursa(job #603026)

Utilizator andrianAndrian andrian Data 14 iulie 2011 04:38:54
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include <iostream>
#include <fstream>
using namespace std;

long p, n2=0, n5=0, n;

int main()
{
    ifstream in("fact.in");
    in >> p;
    long m;
    for(long i=2;n2<p || n5<p;++i)
    {
        n=m=i;
        for(;m%5 == 0;) m/=5, ++n5;
        for(;m%2 == 0;) m/=2, ++n2;
    }
    ofstream out("fact.out");
    if(n2>p && n5>p) out << -1;
    else out << n;
    return 0;
}