Cod sursa(job #189412)

Utilizator ThorRazvan Marinovici Thor Data 14 mai 2008 14:23:14
Problema Factorial Scor 95
Compilator c Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <stdio.h>
#include <stdlib.h>

int calc(int s)
{
	if (s == 0)
		return -1;
    int a = (s / 5) * 4,
        n = a * 5,
        t = a + a/5 + a/ 25 + a/125 + a/ 625 + a/3125  + a/15625 + a/78125 + a/390625 + a/1953125 + a/9765625 + a/48828125 + a/244140625;
    while (t < s)
    {
        n+=5;
        if (n % 244140625 == 0)
            t += 12;
        else if (n % 48828125 == 0)
            t += 11;
        else if (n % 9765625 == 0)
            t += 10;
        else if (n % 1953125 == 0)
            t += 9;
        else if (n % 390625 == 0)
            t += 8;
        else if (n % 78125 == 0)
            t += 7;
        else if (n % 15625 == 0)
            t += 6;
        else if (n % 3125 == 0)
            t += 5;
        else if (n % 625 == 0)
            t += 4;
        else if (n % 125 == 0)
            t += 3;
        else if (n % 25 == 0)
            t += 2;
        else
            t++;
    }
    if (t != s)
        return -1;
    return n;
}

int main()
{
     int nrd;
     FILE *in = fopen("fact.in", "r"),
          *out = fopen("fact.out", "w");
     fscanf(in, "%d", &nrd);
     fprintf(out,"%d", calc(nrd));
     return 0;
}