Cod sursa(job #1925175)

Utilizator waren4Marius Radu waren4 Data 12 martie 2017 15:21:21
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("fact.in"); ofstream g("fact.out");
int p,x; long long i; int a[14];

int main()
{
    a[1]=5;
    for(i=2;i<=13;i++) a[i]=a[i-1]*5;
    f>>p;
    i=5*p;
    x=p;
    int j;
    for(j=2;j<=13;j++) x=x+(i/a[j]);
    while(x>p)
    {
        i-=5;
        x=i/5;
        for(j=2;j<=13;j++) x=x+(i/a[j]);
    }
    if (p==0) g<<1;
    else
    {if (x==p) g<<i;
    if (x<p) g<<-1;}
    return 0;
}