mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Added doctest and more explanation about Dijkstra execution. (#1014)
* Added doctest and more explanation about Dijkstra execution. * tests were not passing with python2 due to missing __init__.py file at number_theory folder * Removed the dot at the beginning of the imported modules names because 'python3 -m doctest -v data_structures/hashing/*.py' and 'python3 -m doctest -v data_structures/stacks/*.py' were failing not finding hash_table.py and stack.py modules. * Moved global code to main scope and added doctest for project euler problems 1 to 14. * Added test case for negative input. * Changed N variable to do not use end of line scape because in case there is a space after it the script will break making it much more error prone. * Added problems description and doctests to the ones that were missing. Limited line length to 79 and executed python black over all scripts. * Changed the way files are loaded to support pytest call. * Added __init__.py to problems to make them modules and allow pytest execution. * Added project_euler folder to test units execution * Changed 'os.path.split(os.path.realpath(__file__))' to 'os.path.dirname()'
This commit is contained in:

committed by
cclauss

parent
2fb3beeaf1
commit
267b5eff40
@ -1,4 +1,22 @@
|
||||
# https://projecteuler.net/problem=234
|
||||
"""
|
||||
https://projecteuler.net/problem=234
|
||||
|
||||
For an integer n ≥ 4, we define the lower prime square root of n, denoted by
|
||||
lps(n), as the largest prime ≤ √n and the upper prime square root of n, ups(n),
|
||||
as the smallest prime ≥ √n.
|
||||
|
||||
So, for example, lps(4) = 2 = ups(4), lps(1000) = 31, ups(1000) = 37. Let us
|
||||
call an integer n ≥ 4 semidivisible, if one of lps(n) and ups(n) divides n,
|
||||
but not both.
|
||||
|
||||
The sum of the semidivisible numbers not exceeding 15 is 30, the numbers are 8,
|
||||
10 and 12. 15 is not semidivisible because it is a multiple of both lps(15) = 3
|
||||
and ups(15) = 5. As a further example, the sum of the 92 semidivisible numbers
|
||||
up to 1000 is 34825.
|
||||
|
||||
What is the sum of all semidivisible numbers not exceeding 999966663333 ?
|
||||
"""
|
||||
|
||||
def fib(a, b, n):
|
||||
|
||||
if n==1:
|
||||
@ -17,16 +35,22 @@ def fib(a, b, n):
|
||||
return c
|
||||
|
||||
|
||||
q=int(input())
|
||||
for x in range(q):
|
||||
l=[i for i in input().split()]
|
||||
c1=0
|
||||
c2=1
|
||||
while(1):
|
||||
|
||||
if len(fib(l[0],l[1],c2))<int(l[2]):
|
||||
c2+=1
|
||||
else:
|
||||
break
|
||||
print(fib(l[0],l[1],c2+1)[int(l[2])-1])
|
||||
|
||||
def solution(n):
|
||||
"""Returns the sum of all semidivisible numbers not exceeding n."""
|
||||
semidivisible = []
|
||||
for x in range(n):
|
||||
l=[i for i in input().split()]
|
||||
c1=0
|
||||
c2=1
|
||||
while(1):
|
||||
if len(fib(l[0],l[1],c2))<int(l[2]):
|
||||
c2+=1
|
||||
else:
|
||||
break
|
||||
semidivisible.append(fib(l[0],l[1],c2+1)[int(l[2])-1])
|
||||
return semidivisible
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for i in solution(int(str(input()).strip())):
|
||||
print(i)
|
||||
|
Reference in New Issue
Block a user