Cod sursa(job #2222637)
| Utilizator | Data | 17 iulie 2018 15:58:40 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int P;
int count5(int x)
{
int p5=5;
int cnt=0;
while(x>=p5)
{
cnt+=(x/p5);
p5*=5;
}
return cnt;
}
int caut(int left,int right)
{
if(right>=left)
{
int mid=left+(right-left)/2;
int nr5=count5(mid);
if(nr5==P)
{
mid-=(mid%5);
return mid;
}
if(nr5>P)return caut(left,mid-1);
else return caut(mid+1,right);
}
return -1;
}
int main()
{
fin>>P;
if(!P)fout<<1;
else{
fout<<caut(1,5*P);
}
return 0;
}
