Cod sursa(job #1198797)

Utilizator teodor440Teodor Tonghioiu teodor440 Data 17 iunie 2014 11:01:45
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <iostream>
#include <fstream>
 
using namespace std;
 
ifstream f("fact.in");
ofstream g("fact.out");
 
int fa(long long x){
    int k=0;
    if(x==0) return 1;
    while(x){
        x/=5;
        k++;
    }
    return k;
}

int main()
{
    long long p,x,a;
    f>>p;
    if(p==0){
        g<<0;
        return 0;
    }
    p++;
    a=0;
    while(p>0){
        p-=fa(a);
        a++;
    }
    a--;
    if(p==0) g<<a*5;
    else g<<-1;

    return 0;
}