`

projecteuler.net第一题

阅读更多
http://projecteuler.net/index.php?section=problems&id=1

projecteuler.net第一题

Add all the natural numbers below one thousand that are multiples of 3 or 5.
求1000以下的能被3或5整除的整数之和.
分享到:
评论
1 楼 lampeter123 2009-07-08  
我的答案是:233168
Java
public class Problem_1 {
        public static void main(String args[]) {
                int sum = 0;
                for (int i =1; i<1000; i++) {
                        if (i%3==0||i%5==0) {
                                sum += i;
                        }
                }
                
                System.out.println(sum);
        }
}


Python
sum(i for i in range(1000) if (i %3==0)or(i%5==0))


相关推荐

Global site tag (gtag.js) - Google Analytics