Cod sursa(job #471413)

Utilizator johnny2008Diaconu Ion johnny2008 Data 18 iulie 2010 18:14:28
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.48 kb
#include<fstream>
using namespace std;
long long a[13]={1,6,31,156,781,3906,19531,97656,488281,2441406,12207031,61035156,305175781};
long long b[13]={5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
int main(){

	long long int n=0,i,p,nr;
	ifstream f("fact.in");
	ofstream g("fact.out");
	f>>p;
	if(p>5){
	for(i=0;i<12;i++){
		if(p>a[i] && p<a[i+1]){
			nr=i;
			i=12;
		}
	}
	
	p=p-a[nr];
	n=b[nr];	
	}
	if(p!=0){
	while(p>0){
		n=n+5;
		p--;
		i=n;
		i=i/5;
		if(i%5==0 && i>0){
			p--;
			i=i/5;
			if(i%5==0 && i>0){
				p--;
				i=i/5;
				if(i%5==0 && i>0){
					p--;
					i=i/5;
					if(i%5==0 && i>0){
						p--;
						i=i/5;
							if(i%5==0 && i>0){
								p--;
								i=i/5;
									if(i%5==0 && i>0 ){
										p--;
										i=i/5;
										if(i%5==0 && i>0){
											p--;
											i=i/5;
											if(i%5==0 && i>0){
												p--;
												i=i/5;
												if(i%5==0 && i>0){
													p--;
													i=i/5;
													if(i%5==0 && i>0){
														p--;
														i=i/5;
														if(i%5==0 && i>0){
															p--;
															i=i/5;
															if(i%5==0 && i>0){
																p--;
																i=i/5;
															}
														}
													}
							
												}
											}
										}
								}
						}
		
					}
				}
			
			}
		
		}
		
	}
	if(p==0){
	g<<n;
	}
	else{
		g<<-1;
	}
	}
	else{
		g<<1;
	}
}