Cod sursa(job #541288)

Utilizator slilverwolfRadu Ghitescu slilverwolf Data 24 februarie 2011 22:55:52
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>

using namespace std;

int zerouri(int n) {
    int suma=0,x;
    x=n;
    while(n) {
        suma+=n%5;
        n/=5;
    }
    return (x-suma)/4;
}

int main() {
    int n,x,z;
    bool gasit=false;
    ifstream f("fact.in");
    f>>n;
    f.close();
    ofstream g("fact.out");
    if(n==0) {
        g<<0;
        g.close();
        return 0;
    }
    x=n*4;
    while((x<n*5) || (gasit==false)) {
        z=zerouri(x);
        if(z==n) {
            gasit=true;
            g<<x;
            g.close();
            return 0;
        }
        else if(z>n){
            break;
        } else {
            x++;
        }
    }
    g<<-1;
    g.close();
    return 0;
}