Cod sursa(job #978720)

Utilizator Alexeu96Alfons Alexandru Alexeu96 Data 29 iulie 2013 15:49:25
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
using namespace std;
#include<fstream>
int main()
{
    ifstream fi("fact.in");
    ofstream fo("fact.out");
    long long a, c, p, b, r, s;
    fi>>p;
    if (p==0) fo<<"1";
    else {
    a=4*p+1;
    b=a/5;
    c=a-5*b;
    if (c!=0) a=a+5-c;
    s=0;
    while (s==0){
    c=5;
    r=0;
    while (c<=a){
        r=r+a/c;
        c=c*5;
    }
    if (r>p) {fo<<"-1"; s=1;}
    else
    if (r==p) { fo<<a; s=1;}
    a=a+5;
    }
    }
    return 0;
}