Cod sursa(job #1809939)

Utilizator turnenTudor Oprescu turnen Data 19 noiembrie 2016 13:51:32
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
using namespace std;
const long long L=30;
ifstream in("fact.in");
ofstream out("fact.out");
int zero(int nr)
{
    int sum=0;
    while(nr)
    {
        nr=nr/5;
        sum=sum+nr;
    }
    return sum;
}
int caut(int l,int x)
{
    int r=0,pas=1<<L;
    while(pas!=0)
    {
        if(r+pas<=l&&zero(r+pas)<x)
        {
            r+=pas;
        }
        pas/=2;
    }
    if(zero(1+r)==x)
    {
        return 1+r;
    }
    else
    {
        return -1;
    }
}
int main()
{
    int n;
    in>>n;
    out<<caut(30,n);

}