-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem46.py
74 lines (60 loc) · 1.31 KB
/
problem46.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def solution():
"""_summary_
Returns:
_type_: _description_
"""
i = 9
while i % 2 != 0:
if not properse(i):
break
i += 2
return i
def properse(n: int) -> bool:
"""Christian Goldbach
that every odd composite
number can be written as the
sum of a prime and twice a square.
>>> properse(33)
>>> True
"""
i = n
while i > 0:
square_number = (n - i) // 2
if is_prime(i) and (n - i) % 2 == 0 and is_square(square_number):
print(f"Odd composite {n} Prime number {i},Square number {square_number}")
return True
i -= 1
return False
def is_prime(n: int) -> bool:
"""Prime
Args:
n (int): _description_
Returns:
bool: _description_
"""
i = 2
while i * i <= n:
if n % i == 0:
return False
i += 1
return True
def is_square(n: int) -> bool:
"""Square
Args:
n (int): _description_
Returns:
bool: _description_
"""
i = 1
if n == 0:
return True
while i * i <= n:
if n / i == i:
return True
i += 1
return False
if __name__ == "__main__":
# print(properse(33))
# print(is_square(16))
# print(is_square(0))
print(solution())