Cod sursa(job #2865347)

Utilizator astridgastrid grun astridg Data 8 martie 2022 19:07:13
Problema Factorial Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{ int n=1,p,nr=0,cn,k=0;
fin>>p;
if(p==0){
    fout<<1;
}
else{
if(p>5000000){
    n=20000005;
    nr=5000000;
}

while(nr<p){
        cn=n;
        k=0;
    while(cn%5==0){
        k++;
        cn=cn/5;
    }
    nr=nr+k;
    //cout<<"testing "<<n<<"\n";
    //cout<<k<<" "<<nr<<"\n";
    n++;
}
if(nr==p){
   fout<<n-1;
}
else{fout<<-1;}
}

    return 0;
}