Project Euler/58: Difference between revisions
From charlesreid1
| Line 8: | Line 8: | ||
==Solution Technique== | ==Solution Technique== | ||
Finding the numbers that lie on the diagonals of the spiral consists of iterating through a vector of integers at intervals of increasing spacing. So all we need to do is implement a counter to generate integers, a variable to keep track of how many integers until the next number on the diagonal, and a method to check if a number is prime. | |||
==Code== | ==Code== | ||
Revision as of 10:07, 8 January 2018
Problem Statement
This question asks about prime spirals.
If we form a spiral with the integers, we find that prime numbers tend to fall on the diagonals of this spiral with a higher density than elsewhere in the spiral. This question asks to find how long it takes before the percentage of integers on the diagonals that are primes falls below 10%.
Link: https://projecteuler.net/problem=58
Solution Technique
Finding the numbers that lie on the diagonals of the spiral consists of iterating through a vector of integers at intervals of increasing spacing. So all we need to do is implement a counter to generate integers, a variable to keep track of how many integers until the next number on the diagonal, and a method to check if a number is prime.
Code
Flags