Cod sursa(job #548075)

Utilizator dtoniucDaniel Toniuc dtoniuc Data 7 martie 2011 08:22:46
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;
int p,n;
int a[13]={0,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
int b[13]={0,6,  31,156, 781, 3906,19531, 97656, 488281,2441406,12207031, 61035156, 305175781};
int main ()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    fin>>p;
    int n=0,nr=1;
	for (int i=0;i<=12;i++)
		if (p==b[i]-1) 
		{
			fout<<"-1";
			nr=0;
		}
	if (nr)
	{
		if (p==0) fout<<"1";
		else
		{
			int i=0;
			while (p>b[i])  i++;
			int s=a[i-1];
			int d=p-b[i-1];
			n=s+d*5;
			fout<<n;
		}
	}
    return 0;
}