Cod sursa(job #1121947)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 25 februarie 2014 14:58:20
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int power(int a, int b)
{
    if(b == 0) return 1;
    if(b == 1) return a;
    int temp = power(a, b/2);
    return temp*temp*power(a, b%2);
}
int main()
{
    int p, pos = 0;
    fin>>p;
    long long int num =  5*p;
    for(int i =0; i< 100;i++)
    {
            if(power(5, i) > p) {pos = i-1;break;}
    }
    num = num - (pos*(pos+1)/2)*5;
    if(p == 0) num = 1;
    fout<<num<<"\n";
    return 0;
}