[欧拉计划]Problem 1.Multiples of 3 and 5
来源:互联网 发布:qq会员永久软件 编辑:程序博客网 时间:2024/05/20 06:27
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.
我感觉还是将自己平时在Project Euler上做的题目整理一下,一是能记录自己的思路,同时也能将想法和别人分享,但我还是希望不要依赖于别人的题解,而努力地尝试自己得到答案,想必这样的收获才是巨大的.
这是道很简单的题目,其实用数学方法可以直接笔算出来:
-容斥原理+等差数列求和
用程序写的话也是非常简短的,在PE上做题的大多使用方便快捷的python做,我不会,因此只好用C++来写(原本想学Haskell的).
代码如下:(再次吐槽MarkDown的语法高亮)
#include<iostream>using namespace std;int main(){ int ans = 0; for(int i = 0; i < 1000; i++) if(i % 3 || i % 5) ans += i; cout << ans << endl; return 0;}
0 0
- [欧拉计划]Problem 1.Multiples of 3 and 5
- 【欧拉计划1】Multiples of 3 and 5
- 欧拉计划(1)Multiples of 3 and 5
- 欧拉项目第一题 Multiples of 3 and 5
- Problem 1:Multiples of 3 and 5
- Problem 1 Multiples of 3 and 5
- 欧拉计划---0001 Multiples of 3 and 5(1000以下3和5的倍数)
- 【Project Euler】【Problem 1】Multiples of 3 and 5
- (Problem 1)Multiples of 3 and 5
- [Project Euler]Problem 1:Multiples of 3 and 5
- Problem 1 Multiples of 3 and 5 (暴力)
- Project Euler Problem 1: Multiples of 3 and 5
- Multiples of 3 and 5
- Multiples of 3 and 5
- Multiples of 3 and 5
- Multiples of 3 and 5
- Multiples of 3 and 5
- [projecteuler]Multiples of 3 and 5
- 19、C语言和设计模式(桥接模式)
- BootStrap模态框
- 九度oj 1461
- Python字符串操作之字符串搜索与替换
- (15.1.13)阅读理解
- [欧拉计划]Problem 1.Multiples of 3 and 5
- 二叉搜索树与双向链表
- TCP三次握手,及其背后的缺陷
- ZOJ2562
- 机器视觉开源代码集合
- HTML与CSS_基础 翁恺 笔记(2015.8.10更新)
- ContentProvider简结
- 学习JavaBean 遇到的问题
- 杭电ACM1394——Minimum Inversion Number