Cod sursa(job #1561942)

Utilizator Andrei2001Andrei Parvulescu Andrei2001 Data 4 ianuarie 2016 18:08:11
Problema Factorial Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <iostream>
#include <stdio.h>
using namespace std;
FILE*f=fopen("fact.in","r");
FILE*g=fopen("fact.out","w");
int main()
{
    int p,n,i=5,ok=0,x,s,z=1;
    fscanf(f,"%d",&p);
    while(z<p) z*=5;
    i=z;
    while (!ok){
        x=i/5; s=0;
        while (x){
            s+=x;
            x/=5;
        }
        if (s==p) {n=i; ok=1;}
        i+=5;
    }
    if (p!=0) fprintf(g,"%d",n);
    else fprintf(g,"1");
    fclose(f);
    fclose(g);
    return 0;
}