Cod sursa(job #1942052)

Utilizator cosminbxCosmin Banu cosminbx Data 27 martie 2017 19:28:23
Problema Factorial Scor 60
Compilator c Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(void)
{
    int ret = 0;

    FILE *fin = NULL;
    FILE *fout = NULL;

    fin = fopen("fact.in", "r");
    if (fin == NULL) {
        ret = -1;
        goto exit;
    }

    fout = fopen("fact.out", "w");
    if (fout == NULL) {
        ret = -1;
        goto exit;
    }

    int32_t p;
    if (fscanf(fin, "%" PRIu32, &p) != 1) {
        ret = -1;
        goto exit;
    }

    int32_t pp = 0;
    int32_t ppp = 0;
    while (pp < p) {
        pp++;
        ppp++;
        int32_t pppp = ppp;
        while (pppp % 5 == 0) {
            pppp /= 5;
            pp++;
        }
    }

    if (pp != p) {
        fprintf(fout, "-1");
    } else {
        if (p == 0) {
            fprintf(fout, "1");
        } else {
            fprintf(fout, "%" PRIu32, ppp * 5);
        }
    }

exit:

    if (fin != NULL) {
        fclose(fin);
    }
    if (fout != NULL) {
        fclose(fout);
    }

    return ret;
}