Pagini recente » Cod sursa (job #162531) | Cod sursa (job #1951831) | Cod sursa (job #2112469) | Cod sursa (job #3253963) | Cod sursa (job #476883)
Cod sursa(job #476883)
#define DEBUG 0
#define GENERATOR 0
#if GENERATOR == 0
#include<fstream>
using namespace std;
/*************************************************************************
* 0 1 2 3 4 5 6 *
* 0 0 6 12 18 24 30 *
* 1 31 37 43 49 55 61 *
* 2 62 68 74 80 86 92 *
* 3 93 99 105 111 117 123 *
* 4 124 130 136 142 148 154 155 *
*************************************************************************/
inline int fact(int zeros)
{
int mod = ((zeros+1)%156);
// From 0 to 155 there are 31 non-numbers
int non = ((zeros+1)/156)*31;
// < 156, if (number+1 % 31) % 6 is zero, it is a non
if ((mod % 31) % 6 == 0) return -1;
if (mod == 155) return -1;
// Add rows
non += (mod / 31) * 6;
// Add elements before
non += (mod % 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 = 110; p < 200; p++) {
out<<"("<<p<<") -> ";
#endif
if (p == 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