Cod sursa(job #81032)

Utilizator coderninuHasna Robert coderninu Data 31 august 2007 00:40:10
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <stdio.h>
#define infile "fact.in"
#define outfile "fact.out"
#define nmax 10000

long p, i, nr, u;
int c[nmax];

void readdata();
void writedata();
void solve();

long add();

int main()
{
 readdata();
 if (!p) { freopen(outfile, "w", stdout); printf("1\n"); fclose(stdout); }
 else
     {
      solve();
      writedata();
     }
 return 0;
}

void readdata()
{
 freopen(infile, "r", stdin);
 scanf("%ld", &p);
 fclose(stdin);
}

void solve()
{
 for (i=5; nr<p; i+=5)
     nr+=add();
}

void writedata()
{
 freopen(outfile, "w", stdout);
 if (nr==p) printf("%d\n", i-5);
 else printf("-1\n");
 fclose(stdout);
}

long add()
{
 c[1]++;
 for (u=1; !(c[u]%5); u++)
     {
      c[u]=0;
      c[u+1]++;
     }
 return u;
}