일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 프로젝트 오일러
- 제곱근의뜻
- 이항분포
- algeomath
- 프랙탈
- 알지오매스
- project euler
- 큰 수의 법칙
- 블록코딩
- 시뮬레이션
- 리만합
- 피타고라스 정리
- 큰수의법칙
- 지오지브라
- 재귀함수
- 상합
- 구분구적법
- 수학탐구
- 작도
- 하합
- 정오각형
- 삼각함수의그래프
- 파이썬
- 오일러
- 확률실험
- counting sunday
- Geogebra
- python
- java
- 몬테카를로
- Today
- Total
이경수 선생님의 수학실험실
Problem 1(Multiples of 3 and 5) 본문
Problem 1(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.
In Python:
sum=0
for i in range(1,1000):
if i%3==0 or i%5==0:
sum+=i
print(sum)
Run time: 0.00024700164794921875 seconds
In Python:
print(sum([i for i in range(1, 1000) if i % 3 == 0 or i % 5 == 0]))
Run time: 0.0010218620300292969 seconds
In Java:
public class Euler1 {
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);
}
}
Run time:
In C#:
using System;
namespace ProjectEuler
{
public class problem01
{
static void Main(string[] args)
{
int sum = 0;
for (int i = 1; i < 1000; i++)
{
if (i % 3 == 0 || i % 5 == 0)
{
sum += i;
}
}
Console.WriteLine(sum);
}
}
}
solution: 233168
[from Project Euler: https://projecteuler.net/problem=1]
'Project Euler' 카테고리의 다른 글
Problem 6(Sum square difference) (0) | 2019.02.08 |
---|---|
Problem 5(Smallest multiple) (0) | 2019.02.08 |
Problem 4(Largest palindrome product) (0) | 2019.02.07 |
Problem 3(Largest prime factor) (0) | 2019.02.06 |
Problem 2(Even Fibonacci numbers) (0) | 2019.02.06 |