Cod sursa(job #1895403)

Utilizator toadehuPuscasu Razvan Stefan toadehu Data 27 februarie 2017 22:28:26
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>

using namespace std;

int pow=5,p,v[100000000];

int main()
{
    ifstream fin ("fact.in");
    ofstream fout ("fact.out");
    fin>>p;
    v[0]=1;
    for (int i=5;i<=100000000;i+=5)
    {
        int val=0;
        if (pow*5>=i)
        {
            pow*=5;
        }
         for (int j=5;j<=pow;j*=5)
         {
             val+=i/j;
         }
         v[val]=i;
         if (val==p)
         {
             fout<<v[val];
             break;
         }
    }
    if (v[p]!=0)
    {
            fout<<v[p];
    }
    else
    {
        fout<<"-1";
    }

}