Rem Find the sum of the digits in the number 100! (Project Euler 20)
p=160
graphsize 1200,5
Dim Prod(p+1)
Prod[0]=1
for b = 1 to 100
for t = 0 to p-1
Prod[t]=Prod[t]*b
next t
Rem Carying
for x = 0 to p-2
While Prod[x]>9
Prod[x]=Prod[x]-10
Prod[x+1]=Prod[x+1]+1
end While
next x
Rem Printing
Print b+"! = ";
for x = 0 to p
Print Prod[p-x];
next x
print
next b
sum=0
for x = 0 to p-1
sum = sum + Prod[x]
next x
print sum
Showing posts with label Euler. Show all posts
Showing posts with label Euler. Show all posts
Wednesday, December 15, 2010
Wednesday, December 8, 2010
Euler 10
Rem Find the sum of all the primes below two million (Project Euler 10)
flag=0
sum=2
print 2+"....Sum="+sum
for h= 2 to 2000000
flag=0
i=1
while flag=0 and i < h^(1/2)
i=i+1
if int(h/i)=h/i then flag=1
end while
if flag=0 then
sum=sum+h
print (h)+"....Sum="+sum
end if
next h
flag=0
sum=2
print 2+"....Sum="+sum
for h= 2 to 2000000
flag=0
i=1
while flag=0 and i < h^(1/2)
i=i+1
if int(h/i)=h/i then flag=1
end while
if flag=0 then
sum=sum+h
print (h)+"....Sum="+sum
end if
next h
Subscribe to:
Posts (Atom)