School Commit Init
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# Solve the problem from the third set here
|
||||
|
||||
def is_prime(n):
|
||||
if n<2:
|
||||
return False
|
||||
for i in range(2,round(n**0.5)+1):
|
||||
if n%i==0:
|
||||
return False
|
||||
return True
|
||||
|
||||
def the_nth_element_of_sequence(n):
|
||||
if n<=0:
|
||||
print("Number should be an positive integer")
|
||||
return None
|
||||
if n==1:
|
||||
print("The nth number in the sequence is: 1")
|
||||
return 1
|
||||
i=1
|
||||
n-=1
|
||||
while n>0:
|
||||
i+=1
|
||||
if is_prime(i):
|
||||
n-=1
|
||||
continue
|
||||
d=2
|
||||
j=i
|
||||
while j>1:
|
||||
if j%d==0:
|
||||
n-=d
|
||||
while j%d==0:
|
||||
j//=d
|
||||
if n<=0:
|
||||
i=d
|
||||
break
|
||||
d+=1
|
||||
if n<=0:
|
||||
print("The nth number in the sequence is: {}".format(i))
|
||||
return i
|
||||
|
||||
if __name__=="__main__":
|
||||
n=int(input("Please enter an positive integer number: "))
|
||||
the_nth_element_of_sequence(n)
|
||||
Reference in New Issue
Block a user