Cod sursa(job #2074495)

Utilizator DavvDrgDavid Dragostin DavvDrg Data 24 noiembrie 2017 17:47:52
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <fstream>

using namespace std;
int pow5(int x)
{
    int cnt=0;
    while(x>0)
    {
        cnt+=x/5;
        x=x/5;
    }
    return cnt;
}
ifstream cin("fact.in");
ofstream cout("fact.out");
int main()
{
    int n,x=0,pas=1<<30;
    cin>>n;
    while(pas)
    {
        if(pow5(x+pas)<n)
            x=x+pas;
        pas=pas/2;
    }
    if(pow5(x+1)==n)
        cout<<x+1;
    else
        cout<<"-1";
    return 0;
}