2007年4月10日星期二

using python to solve problem on math(1)

"""
If we list all the natural numbers below 10 that are multiples of 3 or 5,
we get 3, 5, 6 and 9. The sum of these multiples is 23.
 
Find the sum of all the multiples of 3 or 5 below 1000.
 
my saying:
my solution can be changed easily,but I do not think it is a good answer,becase it compares more than it should be
"""
base=[3,5]
cur=2
maxnum=1000
result=[]
 
while cur<maxnum:
 for i in base:
  if cur/i==float(cur)/i:
   result.append(cur)
   break
 cur+=1
 
print result
print sum(result)
 

没有评论: