Cod sursa(job #476848)

Utilizator chibicitiberiuChibici Tiberiu chibicitiberiu Data 12 august 2010 14:48:21
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.33 kb
#define DEBUG 0
#define GENERATOR 0

#if GENERATOR == 0
#include<fstream>
using namespace std;

inline int fact(int zeros)
{
    int non = ((zeros + 1) / 31) * 6;
    non += ((zeros+1) % 31) / 6;
    return (zeros - non)*5;
}

int main()
{
    int p;
    ifstream in ("fact.in");
    ofstream out ("fact.out");
    in>>p;

#if DEBUG == 1
    for (p = 0; p < 100; p++) {
        out<<"("<<p<<") -> ";
#endif
        if (p == 0) out<<1;
        else if (((p+1)%31)%6 == 0) out<<-1;
        else out<<fact(p);
#if DEBUG == 1
        out<<endl;
    }
#endif
    out.close();
    return 0;
}

#endif

#if GENERATOR == 1
#include<iostream.h>
#include<fstream.h>

ofstream out("fact.out");

int main()
{
    for (int p = 0; p < 10000; p++) {
            int ok=0,n,twos=0,fives=0,pp;


            for(n=1;ok==0 && n>0;n++)
            {
                    pp=n;
                    while(pp%5==0 || pp%2==0){
                            if (pp%2==0) { twos++; pp=pp/2;}
                            if (pp%5==0) { fives++; pp=pp/5;}
                            }

                    if(twos>=p && fives>=p) ok=n;
            }

            out<<"("<<p<<")"<<" -> ";
            if(ok==0) out<<-1;
            else out<<ok;
            out<<endl;

            if (p%1000 == 0) cout<<"\rLoading..."<<p*100/10000<<"%";
    }
    
    out.close();


    return 0;
}
#endif