Cod sursa(job #2794650)
| Utilizator | Data | 5 noiembrie 2021 11:28:54 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int p,sol=-1;
int pow(int a)
{
long long q=5;
int c=0;
while (q<=a)
{c=c+a/q;
q*=5;}
return c;
}
int main()
{
fin >>p;
int left=1,right=5*p;
while (left<=right)
{int mid=(left+right)/2;
if (p<=pow(mid)) {right=mid-1;
if (pow(mid)==p) sol=mid;}
else {left=mid+1;}}
if (p==0) sol=1;
fout <<sol;
return 0;
}
