Mai intai trebuie sa te autentifici.
Cod sursa(job #1562158)
| Utilizator | Data | 4 ianuarie 2016 20:51:25 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <iostream>
#include <stdio.h>
using namespace std;
FILE*f=fopen("fact.in","r");
FILE*g=fopen("fact.out","w");
int main()
{
int p,n,ok=0,x,st=5,dr,s,m,z=1;
fscanf(f,"%d",&p);
dr=5*p;
while (ok==0&&st<=dr){
m=(st+dr)/2;
if (m%5!=0) m-=2;
x=m/5; s=0;
while (x){
s+=x;
x/=5;
}
if (s==p) {n=m; ok=1;}
else if (s<p) st=m+5;
else dr=m-5;
}
if (st>dr) n=-1;
if (p!=0) fprintf(g,"%d",n);
else fprintf(g,"1");
fclose(f);
fclose(g);
return 0;
}
