W pierwszym 1366. W drugim 648.
Sposób liczenia (kod w Pythonie 3.2):
Kod: Zaznacz cały
a = list(str(2**1000))
a = map(int, a)
print(sum(a))
from math import factorial
b = list(str(factorial(100)))
b = map(int, b)
print(sum(b))
Kod: Zaznacz cały
a = list(str(2**1000))
a = map(int, a)
print(sum(a))
from math import factorial
b = list(str(factorial(100)))
b = map(int, b)
print(sum(b))
Kod: Zaznacz cały
#include <stdio.h>
int pow(int * w, int n, int k){
int lc=0; w[0]=1;
while(k>0) {
int i, c= 0;
for(i=0; i<=lc; i++){
c += w[i]*n;
w[i] = c%10; c /= 10;}
while(c){
w[i++]= c%10; c /= 10;}
lc = i-1; k--;}
return lc; }
int fac(int * w, int n){
int lc=0; w[0]=1;
while(n>1){
int i, c=0;
for(i=0; i<=lc; i++){
c += w[i]*n;
w[i] = c%10; c /= 10; }
while(c){
w[i++]= c%10; c /= 10; }
lc = i-1; n--; }
return lc; }
int sum(int * w, int d){
int s=w[0];
while(d>0)
s += w[d--];
return s; }
int main(void) {
int w[303];
int d=pow(w, 2, 1000);
printf("s(2^n)=%d
", sum(w, d));
d=fac(w, 100);
printf("s(n!)= %d
", sum(w, d));
return 0;}