วันพุธที่ 23 กันยายน พ.ศ. 2552

Project Euler Q20

here's the question.

n! means n × (n − 1) × ... × 3 × 2 × 1

Find the sum of the digits in the number 100!


And my version of Lua for window, kinda hard to add more library to it, so I can't just get the BigInt and do the simple coding.

I google the amount of 100! instead and do the lazy man way.


here's the code,

---------------------------------------

z=0

a = "93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"
length = string.len(a)
for i=1, length do
z=z+a:byte(i)-("0"):byte(1)
end
print(z)


ไม่มีความคิดเห็น:

แสดงความคิดเห็น