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

Project Euler 58をPythonでやってみる

More than 1 year has passed since last update.

問題58

英語
https://projecteuler.net/problem=58
日本語
http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2058

解答58

正直そこまで工夫はしていません。
4つ進むごとに増加する値が2増える数列になっているのでその通りに進めていき、1周ごとに10%未満になるか調べるだけです。

コードは次のようになります。

ProjectEuler51.py
import math

def is_prime(n):
    for k in range(3, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


dist = 4
num_of_prime = 3
num_of_all =5
num = 9
while 10*num_of_prime >= num_of_all:
    for i in range(0,3):
        num += dist
        if is_prime(num):
            num_of_prime += 1
    num += dist
    num_of_all += 4
    dist += 2

print(dist-1)

8.469 seconds

you1111
Why not register and get more from Qiita?
  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
No 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
ユーザーは見つかりませんでした