Cod sursa(job #1168439)

Utilizator Radu551Radu Besleaga Radu551 Data 8 aprilie 2014 16:45:49
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
#include<algorithm>

using namespace std;

int main()
{
    FILE *fin,*fout;
    fin=fopen("fact.in","r");

    fout=fopen("fact.out","w");
    int n,p,p5,cx,x;
    fscanf(fin,"%d",&p);
    if(p==0)fprintf(fout,"1");
    else
    {
        p5=0;
        x=5;
        while(p5<p)
        {
            cx=x;
            if(cx%3125==0)
            {
                p5=p5+5;
                cx=cx/3125;
            }
            if(cx%625==0){
                p5=p5+4;
                cx=cx/625;
            }
             if(cx%125==0)
            {
                p5=p5+3;
                cx=cx/125;
            }
            if(cx%25==0){
                p5=p5+2;
                cx=cx/25;
            }
             if(cx%5==0)
            {
                p5=p5+1;
                cx=cx/5;
            }

            if(p5<p) x=x+5;
            else fprintf(fout,"%d",x);

        }
    }


    fclose(fin);
    fclose(fout);
    return 0;
}