Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 오일러 프로젝트
- 오토인코더
- 역전파
- Autoencoder
- 딥러닝
- SQL
- 베이지안
- 자전거 여행
- mnist
- 냥코 센세
- 합성곱 신경망
- 소수
- Convolutional Neural Network
- c#
- deep learning
- CNN
- 수달
- 히토요시
- 역전파법
- Python
- 소인수분해
- backpropagation
- bayesian
- neural network
- Gram matrix
- 신경망
- 비샤몬당
- A Neural Algorithm of Artistic Style
- project euler
- 전처리
Archives
- Today
- Total
통계, IT, AI
23. Non-abundant sums 본문
1. 개요
문제는 이곳에서 확인할 수 있다. 어떤 자연수
28123보다 큰 정수는 abundant number 두개의 합으로 나타낼 수 있다는 것이 증명되었지만 상한선은 알려지지 않았다. 이때 두 abundant number의 합으로 나타낼 수 없는 자연수의 합을 구하는 것이 문제의 목표이다.
2. 구현: ver 1.0
어떤 자연수가 두 abundant number의 합으로 표현되는지 확인하는 식으로 구현하려고 했는데 속도가 느렸다. 대안으로 두 abundant number의 합으로 표현되는 수를 모두 구하는 식으로 진행하였다.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # -*- coding: utf-8 -*- import math as m # 1. proper divisors의 합을 구하는 함수를 정의한다. def sum_of_proper_divisors(n): """ INPUT: natural number n OUTPUT: sum of proper divisors of n """ divisor = 2 sum_of_divisors = 1 lim = m.sqrt(n) while divisor < lim: quotient, remainder = divmod (n, divisor) if remainder = = 0 : sum_of_divisors + = divisor + quotient divisor + = 1 if divisor = = lim: sum_of_divisors + = divisor return sum_of_divisors # 2. 위에서 구한 함수를 이용하여 28124보다 작은 abundant number를 구한다. abundant_number_list = list () for n in range ( 12 , 28124 ): if n < sum_of_proper_divisors(n): abundant_number_list.append(n) # 3. abundant number의 합으로 나타낼 수 있는 자연수를 구한다. sum_of_abundant_number_list = list () for i in range ( 0 , len (abundant_number_list)): for j in range (i, len (abundant_number_list)): a_i = abundant_number_list[i] a_j = abundant_number_list[j] s = a_i + a_j if s > 28123 : break sum_of_abundant_number_list.append(s) # 4. 중복된 수를 제외하고 모두 더하여 답을 구한다. print ( 28123 * 28124 / / 2 - sum ( set (sum_of_abundant_number_list))) |
답은 4179871이다.
'IT > PROJECT_EULER' 카테고리의 다른 글
25. 1000-digit Fibonacci number (0) | 2017.01.28 |
---|---|
24. Lexicographic permutations (0) | 2017.01.27 |
21. Amicable numbers (0) | 2017.01.23 |
19. Counting Sundays, 20. Factorial digit sum (0) | 2017.01.18 |
18. Maximum path sum I (0) | 2017.01.15 |
Comments