Cod sursa(job #3276827)
| Utilizator | Data | 14 februarie 2025 19:44:36 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.65 kb |
#include<fstream>
using namespace std;
int countZeroes(int N){
int count=0;
while(N>=5){
count+=N/5;
N/=5;
}
return count;
}
int main(){
ifstream fin("fact.in");
ofstream fout("fact.out");
int P;
fin>>P;
if(P==0){
fout<<"1\n";
return 0;
}
int left=0,right=P*5,ans=-1;
while(left<=right){
int mid=(left+right)/2;
int zeroes=countZeroes(mid);
if(zeroes==P){
ans=mid;
right=mid-1;
}
else if(zeroes<P){
left=mid+1;
}
else{
right=mid-1;
}
}
fout<<ans<<"\n";
return 0;
}
