Pagini recente » Cod sursa (job #2441909) | Cod sursa (job #598348) | Cod sursa (job #1392138) | Cod sursa (job #3125873) | Cod sursa (job #639650)
Cod sursa(job #639650)
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int p;
int rez(int n)
{
int r = 0;
while(n>=5)
{
r+=n/5;
n/=5;
}
return r;
}
int cauta (int p)
{
int i,pas=1<<30;
for(i=0;pas!=0;pas/=2)
{
if(rez(i+pas)<p)
i+=pas;
}
return i+1;
}
int main()
{
in>>p;
int q=cauta(p);
if(rez(q)!=p)
out<<-1;
else out<<q;
return 0;
}