MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_064/sol1.py:47–72  ·  view source on GitHub ↗

Returns the count of numbers <= 10000 with odd periods. This function calls continuous_fraction_period for numbers which are not perfect squares. This is checked in if sr - floor(sr) != 0 statement. If an odd period is returned by continuous_fraction_period, count_odd_period

(n: int = 10000)

Source from the content-addressed store, hash-verified

45
46
47def solution(n: int = 10000) -> int:
48 """
49 Returns the count of numbers <= 10000 with odd periods.
50 This function calls continuous_fraction_period for numbers which are
51 not perfect squares.
52 This is checked in if sr - floor(sr) != 0 statement.
53 If an odd period is returned by continuous_fraction_period,
54 count_odd_periods is increased by 1.
55
56 >>> solution(2)
57 1
58 >>> solution(5)
59 2
60 >>> solution(7)
61 2
62 >>> solution(11)
63 3
64 >>> solution(13)
65 4
66 """
67 count_odd_periods = 0
68 for i in range(2, n + 1):
69 sr = sqrt(i)
70 if sr - floor(sr) != 0 and continuous_fraction_period(i) % 2 == 1:
71 count_odd_periods += 1
72 return count_odd_periods
73
74
75if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 2

floorFunction · 0.90

Tested by

no test coverage detected