Cod sursa(job #2056615)

Utilizator mdcoroiuCoroiu Mircea-Dumitru mdcoroiu Data 4 noiembrie 2017 12:30:53
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<iostream>
#include<fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

int main(){
    int p,c0=0,i=1,fact=1;
    f>>p;
    if(p==0) g<<1;
    else{
        while(c0<p){
            fact=fact*(++i);
            //g<<i<<" "<<fact<<"\n";
            while(fact%10==0) {
                c0++;
                fact=fact/10;
            }
            fact=fact%1000;
        }
        if(c0==p) g<<i;
        else g<<-1;
    }
    f.close();g.close();
    return 0;
}