Cod sursa(job #940008)
| Utilizator | Data | 15 aprilie 2013 13:50:14 | |
|---|---|---|---|
| Problema | Factorial | Scor | 85 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
unsigned pow(unsigned a,unsigned b);
int main()
{
unsigned n,p,i,s=0;
unsigned v[100];
f>>p;
if(p==0) {g<<1; return 0;}
v[1]=1;
i=1;
while(p>v[i])
{
i++;
v[i]=v[i-1]*5+1;
}
i--;
while(i&&p)
{
while(p>=v[i])
{ s+=pow(5,i); p-=v[i];}
i--;
}
g<<s;
return 0;
}
unsigned pow(unsigned a,unsigned b)
{
unsigned s=1;
while(b)
{
s*=a;
b--;
}
return s;
}