2019-07-16 23:09:53 +00:00
|
|
|
"""
|
|
|
|
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 ?
|
|
|
|
"""
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2019-06-16 13:19:20 +00:00
|
|
|
def fib(a, b, n):
|
2019-10-05 05:14:13 +00:00
|
|
|
|
|
|
|
if n == 1:
|
2019-06-16 13:19:20 +00:00
|
|
|
return a
|
2019-10-05 05:14:13 +00:00
|
|
|
elif n == 2:
|
2019-06-16 13:19:20 +00:00
|
|
|
return b
|
2019-10-05 05:14:13 +00:00
|
|
|
elif n == 3:
|
|
|
|
return str(a) + str(b)
|
|
|
|
|
2019-06-16 13:19:20 +00:00
|
|
|
temp = 0
|
2019-10-05 05:14:13 +00:00
|
|
|
for x in range(2, n):
|
|
|
|
c = str(a) + str(b)
|
2019-06-16 13:19:20 +00:00
|
|
|
temp = b
|
|
|
|
b = c
|
|
|
|
a = temp
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
2019-07-16 23:09:53 +00:00
|
|
|
def solution(n):
|
|
|
|
"""Returns the sum of all semidivisible numbers not exceeding n."""
|
|
|
|
semidivisible = []
|
|
|
|
for x in range(n):
|
2019-10-05 05:14:13 +00:00
|
|
|
l = [i for i in input().split()]
|
|
|
|
c2 = 1
|
|
|
|
while 1:
|
|
|
|
if len(fib(l[0], l[1], c2)) < int(l[2]):
|
|
|
|
c2 += 1
|
2019-07-16 23:09:53 +00:00
|
|
|
else:
|
|
|
|
break
|
2019-10-05 05:14:13 +00:00
|
|
|
semidivisible.append(fib(l[0], l[1], c2 + 1)[int(l[2]) - 1])
|
2019-07-16 23:09:53 +00:00
|
|
|
return semidivisible
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
for i in solution(int(str(input()).strip())):
|
|
|
|
print(i)
|