Cod sursa(job #1122496)

Utilizator alin.18Chedea Alin alin.18 Data 25 februarie 2014 18:32:00
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");


int main()
{
    int s=0, i, n, t=2, w;
    long int  p ;
    f>>p;
    
    if(p==0) g<<1;
    else
    {
        for(w=5; w<=4*p; w*=5) 
        s+=(4*p)/w;
        t=4*p+1;
        
        while(s<p)
        {
            n=i; w=0;
            while(n%5==0) {n/=5; w++;}
            s+=w;
            t++;
        }
        if(s==p) g<<t-1;
        else g<<-1;
    }
    
    return 0;
}