Cod sursa(job #1238219)

Utilizator afkidStancioiu Nicu Razvan afkid Data 5 octombrie 2014 23:06:57
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <cstdio>

using namespace std;

const char InFile[]="fact.in";
const char OutFile[]="fact.out";

int p;

int main()
{
    freopen(InFile,"r",stdin);
    freopen(OutFile,"w",stdout);
    scanf("%d",&p);
    int n=1,cnt=1;
    if(p==0)
        printf("1\n");
    else{
        while(cnt<p)
        {
            int t=++n;
            while(t%5==0 && t!=0)
                {
                    t/=5;
                    cnt++;
                }
            cnt++;
        }
        if(cnt==p)
            printf("%d\n",5*n);
        else printf("-1\n");
    }
    return 0;
}