Mai intai trebuie sa te autentifici.
Cod sursa(job #1325767)
Utilizator | Data | 24 ianuarie 2015 12:46:25 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.76 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n,i,j,p;
int cautbin(long long a,long long b)
{
if(a>b)
return -1;
int m=(a/5+b/5)/2;
m*=5;
int x=5;
int pa,pb,pm;
pa=pb=pm=0;
while(a/x!=0)
{
pa+=a/x;
x*=5;
}
x=5;
while(b/x!=0)
{
pb+=b/x;
x*=5;
}
x=5;
while(m/x!=0)
{
pm+=m/x;
x*=5;
}
x=5;
if(pm>n)
return cautbin(a,m-5);
else
if(pm<n)
return cautbin(m+5,b);
else
return m;
}
int main()
{
f>>n;
if(n==0)
g<<"1"<<'\n';
else
{
g<<cautbin(0,n*5)<<'\n';
}
return 0;
}