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
- A Neural Algorithm of Artistic Style
- 히토요시
- SQL
- 베이지안
- 역전파
- 비샤몬당
- c#
- backpropagation
- Convolutional Neural Network
- Autoencoder
- Python
- 합성곱 신경망
- 냥코 센세
- project euler
- CNN
- 딥러닝
- 신경망
- 자전거 여행
- deep learning
- 전처리
- 소수
- Gram matrix
- 역전파법
- bayesian
- neural network
- 소인수분해
- mnist
- 오토인코더
- 수달
- 오일러 프로젝트
Archives
- Today
- Total
통계, IT, AI
[Project Euler] 46. Goldbach's other conjecture 본문
1. 개요
문제는 이곳에서 확인할 수 있다. odd composite number는 소수가 아닌 홀수인데, 골든바흐는 odd composite number를 아래와 같이 어떤 소수 \(p\)와 어떤 수 \(k\)의 제곱의 두배의 합으로 표현할 수 있을 것이라고 추측하였다.
\(9=7+2\times 1^2\)
\(15=7+2\times 2^2\)
\(21=3+2\times 3^2\)
\(25=7+2\times 3^2\)
\(27=19+2\times 2^2\)
\(33=31+2\times 1^2\)
하지만 이 추측은 틀렸다. 이 추측에 맞지 않는 가장 작은 odd composite number를 찾는 것이 문제의 목표이다.
2. 구현
앞선 문제와 마찬가지로 에라스토테네스의 체를 사용하여 소수를 구한다.
# -*- coding: utf-8 -*- class Prime: def __init__(self): init_max_int = 2 self.is_prime = bytearray([1]) * (init_max_int+1) self.is_prime[0] = self.is_prime[1] = 0 self.make_more_prime() def make_more_prime(self): self.is_prime += bytearray([1])*(len(self.is_prime)+1) max_int = len(self.is_prime)-1 for i in range(2, int(max_int**1/2)+1): if self.is_prime[i]: m = max_int//i - i + 1 self.is_prime[i**2::i] = bytearray([0])*m p = Prime() n = 9 # first odd composite number while True: while len(p.is_prime) <= n: p.make_more_prime() if not p.is_prime[n] and not n % 2 == 0: for idx in range(n-2, 0, -2): k = ((n - idx)/2)**0.5 if p.is_prime[idx] and k % 1 == 0: print('{n} = {prime} + 2*{k}^2'.format(n=n, prime=idx, k=int(k))) break else: print('ANSWER: {answer}'.format(answer=n)) quit() n += 2
답은 5777이다.
'IT > PROJECT_EULER' 카테고리의 다른 글
[Project Euler] 49. Prime permutations (0) | 2017.05.14 |
---|---|
[Project Euler] 47. Distinct primes factors, 48. Self powers (0) | 2017.05.10 |
[Project Euler] 45. Triangular, pentagonal, and hexagonal (0) | 2017.05.07 |
[Project Euler] 44. Pentagon numbers (0) | 2017.05.05 |
[Project Euler] 43. Sub-string divisibility (0) | 2017.05.01 |
Comments