sol1 Algorithm

The sol1 Algorithm, also known as "Squaring the Circle" algorithm, is a mathematical technique that aims to solve the ancient geometrical problem of constructing a square with the same area as a given circle using only compass and straightedge. This algorithm is based on the approximation of the value of Pi (π), which is the ratio of the circumference of a circle to its diameter. The main idea behind the sol1 Algorithm is to find the side length of a square that, when multiplied by itself, gives the same area as that of a circle with a given radius. The sol1 Algorithm begins by drawing a circle with the desired radius, followed by constructing an inscribed square within the circle. The next step involves dividing the circle's circumference into a number of equal segments, which are then used to create a polygon that approximates the circle. The area of this polygon can be easily calculated using basic trigonometry, and as the number of segments increases, the approximation of the circle's area becomes more accurate. Finally, the side length of the square is determined by finding the square root of the approximated circle's area, and a square with this side length is constructed using a compass and straightedge. Although the sol1 Algorithm provides an approximation to the problem of squaring the circle, it has been proven mathematically impossible to achieve an exact solution using only compass and straightedge due to the transcendental nature of the number π.
"""
Problem Statement:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.
"""
from math import sqrt


def is_prime(n):
    for i in range(2, int(sqrt(n)) + 1):
        if n % i == 0:
            return False

    return True


def sum_of_primes(n):
    if n > 2:
        sumOfPrimes = 2
    else:
        return 0

    for i in range(3, n, 2):
        if is_prime(i):
            sumOfPrimes += i

    return sumOfPrimes


def solution(n):
    """Returns the sum of all the primes below n.

    # The code below has been commented due to slow execution affecting Travis.
    # >>> solution(2000000)
    # 142913828922
    >>> solution(1000)
    76127
    >>> solution(5000)
    1548136
    >>> solution(10000)
    5736396
    >>> solution(7)
    10
    """
    return sum_of_primes(n)


if __name__ == "__main__":
    print(solution(int(input().strip())))

LANGUAGE:

DARK MODE: