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 |
Tags
- 신경망
- 소수
- mnist
- 역전파
- 자전거 여행
- neural network
- 오일러 프로젝트
- Autoencoder
- 수달
- CNN
- 소인수분해
- 오토인코더
- 전처리
- bayesian
- SQL
- A Neural Algorithm of Artistic Style
- 합성곱 신경망
- 역전파법
- backpropagation
- 비샤몬당
- Python
- Gram matrix
- Convolutional Neural Network
- 히토요시
- deep learning
- 베이지안
- 딥러닝
- c#
- 냥코 센세
- project euler
Archives
- Today
- Total
통계, IT, AI
21. Amicable numbers 본문
1. 개요
문제는 이곳에서 확인할 수 있다. 자연수 \(n\)보다 작으면서 \(n\)을 나누어 떨어지게 하는 수를 proper divisor라고 하자. 그리고 \(d(n)\)을 \(n\)에 관한 proper divisors의 합이라고 정의하자. 이때 서로 다른 \(a\)와 \(b\)에 대하여 \(d(a)=b\), \(d(b)=a\)의 관계가 있을 때 \(a\)와 \(b\)를 amicable numbers라고 한다. 예를 들어, \(d(220)=284\), \(d(284)=220\)이므로 220과 284는 amicable numbers이다. 10000보다 작은 amicable numbers의 합을 구하는 것이 문제의 목표이다.
2. Ver 1.0
\(d(n)\)을 정의할 때, 처음에는 소수를 사용하는 방법을 생각했다. 그런데 포스팅을 위하여 다시 보니 불필요하게 복잡한 구현인 듯 하여 좀 더 쉬운 방법을 선택하였다.
# -*- coding: utf-8 -*- import math as m # 1. Define d(n) def d(n): lim = m.sqrt(n) divisor = 2 result = 1 while divisor <= lim: quotient, remainder = divmod(n, divisor) if remainder == 0: result += (divisor + quotient) divisor += 1 if (divisor - 1) == lim: result -= divisor return result # 2. Evaluate the sum of all the amicable numbers under 10000. d_set = dict() for n in range(2, 10000): d_set[n] = d(n) result = 0 for k, v in d_set.items(): if v in d_set and k != v and d_set[v] == k: print('Amicable number: ', k, v) result += k print(result)
답은 31626이다.
'IT > PROJECT_EULER' 카테고리의 다른 글
24. Lexicographic permutations (0) | 2017.01.27 |
---|---|
23. Non-abundant sums (0) | 2017.01.27 |
19. Counting Sundays, 20. Factorial digit sum (0) | 2017.01.18 |
18. Maximum path sum I (0) | 2017.01.15 |
17. Number letter counts (0) | 2017.01.12 |
Comments