Help us understand the problem. What is going on with this article?

Project Euler 50「連続する素数の和」

More than 1 year has passed since last update.

@cof さんに頂いたコメント内の関数(get_prime_boolean)を丸パクリ。
いやはや、よくできてますねこの関数。美しいです。
ちゃんと内容理解したからコピペしちゃっていいですよね。

Problem 50 「連続する素数の和」

素数41は6つの連続する素数の和として表せる:
41 = 2 + 3 + 5 + 7 + 11 + 13.
100未満の素数を連続する素数の和で表したときにこれが最長になる.
同様に, 連続する素数の和で1000未満の素数を表したときに最長になるのは953で21項を持つ.
100万未満の素数を連続する素数の和で表したときに最長になるのはどの素数か?

def hoge(num):
    primes = [ i for i, b in enumerate(get_prime_boolean(num)) if b ]
    cnt, ans = 1, 0
    for n in range(len(primes)):
        if primes[n] > num / cnt: break
        for m in range(n + cnt, len(primes) + 1):
            N = sum(primes[n:m])
            if N >= num: break
            if m - n > cnt and N in primes:
                cnt, ans = m - n, N
    return ans

def get_prime_boolean(search_max):
    prime_boolean = [False,False] + [True] * (search_max-1)
    prime_boolean[4::2] = [False] * (len(prime_boolean[4::2]))
    p = 3
    p_max = int(search_max ** 0.5) + 1
    while p <= p_max:
        if prime_boolean[p]:
            prime_boolean[p**2::p] = [False] * (len(prime_boolean[p**2::p]))
        p += 2
    return prime_boolean

print(hoge(1000000))
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away