1 Multiples of 3 and 5 - Project Euler
来源:互联网 发布:网络传真软件破解版 编辑:程序博客网 时间:2024/05/19 20:41
Multiples of 3 and 5
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.
package xxx.xxx.xxx;
public class MultiplesOf {
private int compute(int range, int a, int b) {
int sum = 0;
for (int i = 1; i < range; i++) {
if (i % a == 0 || i % b == 0) {
System.out.println(i);
sum = sum + i;
}
}
return sum;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MultiplesOf mul = new MultiplesOf();
System.out.println(mul.compute(1000, 3, 5));
}
}
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.
package xxx.xxx.xxx;
public class MultiplesOf {
private int compute(int range, int a, int b) {
int sum = 0;
for (int i = 1; i < range; i++) {
if (i % a == 0 || i % b == 0) {
System.out.println(i);
sum = sum + i;
}
}
return sum;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MultiplesOf mul = new MultiplesOf();
System.out.println(mul.compute(1000, 3, 5));
}
}
0 0
- 【Project Euler】【Problem 1】Multiples of 3 and 5
- [Project Euler]Problem 1:Multiples of 3 and 5
- Project Euler #1: Multiples of 3 and 5
- 1 Multiples of 3 and 5 - Project Euler
- Project Euler Problem 1: Multiples of 3 and 5
- Project Euler 001 Multiples of 3 and 5
- Priject Euler problem 1:multiples of 3 or 5
- Problem 1:Multiples of 3 and 5
- PE 1 Multiples of 3 and 5
- 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
- 【欧拉计划1】Multiples of 3 and 5
- (Problem 1)Multiples of 3 and 5
- 欧拉计划(1)Multiples of 3 and 5
- iOS中常见的3种循环引用情况
- 第四章 处理器体系结构
- Oauth与Shiro整合的开源项目
- 第五章 优化程序性能
- python 环境的配置和pip 的安装
- 1 Multiples of 3 and 5 - Project Euler
- JavaEE之JDBC编程[详解]
- 面试题:一数组arr,长度为len, 已知 0<=a<=b<len , 求 arr[b]-arr[a] 最大值?
- 黑马程序员--OC之内存管理
- LEETCODE-Factorial Trailing Zeroes
- 文章标题
- 数据库的锁机制
- Android之如何成为Android高手
- 第二阶段开始!!!!!!~~~~~~~~~~