- #1

Arman777

Gold Member

- 1,735

- 138

## Homework Statement

https://projecteuler.net/problem=58

## Homework Equations

## The Attempt at a Solution

Python:

```
def prime(N):
if N == 1:
return False
y = int(N**0.5)
for i in range(2,y+1):
if N%i == 0:
return False
return True
def finder(N):
L = len(N)
count = 0
for i in N:
if prime(i) == True:
count += 1
return count
J = 13296
D1 = [(2*n+1)**2 for n in range(1,J)] #diagonal 1
D2 = [4*n**2+1 for n in range(1,J)] #diagonal 2
D3 = [4*n**2+2*n+1 for n in range(1,J)] #diagonal 3
D4 = [(4*n**2)-(2*n)+1 for n in range(1,J)] #diagonal 4
f = finder(D1) + finder(D2) + finder(D3) + finder(D4) #sum of primes in the diagonals
d = f/((J-1)*4+1) #sum of primes divided by lenght of the diagonals
if d < 0.10: #percent thing
print(d) #the percantage
print((J-1)*2+1) #side lenght of the square
```

At trial 13296 I should have the correct result but it seems wrong I dont know why

İf you put J = 4 you ll get the result as the question does

Last edited by a moderator: