Cod sursa(job #1156387)

Utilizator petrasromanPetras Roman petrasroman Data 27 martie 2014 17:07:32
Problema Factorial Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.69 kb
#include <fstream>
#include <cmath>

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long unsigned i,mouse,k,p,j;
/*int fdghjgh(int step,int place)
{
    if(place==p)
    {
        return
    }
    else
    {
        while(place<p)
        {
            place+=step;
        }
        if(step!=1)
        return fdghjgh((step-1)/5,place-step)
    }
}*/
int main()
{
    fin>>p;
    /*for(i=1;i<=630;i++)
    {p*=i;if(i%5==0){cout<<i<<" "<<p<<'\n';p=1;
    }}p=4;*/
     for(i=5;i<=80000010;i+=5)
    {
        if(k+5>p)
        {
            for(j=i-5+1;j<=i;j++)
            {
                mouse=j;
                k++;
                while(!(mouse%5))
                {mouse/=5;k++;}
                if((k==p)){fout<<j*5;return 0;}
    }fout<<-1;return 0;
        }
        k+=5;mouse=i;
        while(!(mouse%5))
        {mouse/=5;k++;}
        if((k==p)){fout<<i*5;return 0;}
    }
    fout<<-1;/*s=1;
    while(p>=s)
    {
        s=s*5+1;k++;
    }
    fdghjgh((s-1)/5,(s-1)/5);*/
    return 0;
}
/*if(!(k%100000000)){cout<<i/5;return 0;}*/
//1   1   1    1    2     1    1    1     1    2    1    1    1    1    2    1     1    1    1    2    1     1     1      1     3    1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 4
//5   10  15   20   25    30   35   40    45   50   55   60   65   70   75   80    85   90   95  100  105   110   115    120   125
//1   2   3    4    6     7    8    9     10   12   13   14   15   16   18   19    20   21   22   24   25    26    27     28    31