We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# Enter your code here. Read input from STDIN. Print output to STDOUTimportmathasmimportsysdeflps(n):ref=m.floor(m.sqrt(n))result=1temp=[]foriinrange(2,ref+1):#lets find out the greatest prime no less than refforjinrange(2,i):ifi%j==0:breakelse:#thiselseisforFORlooptemp.append(i)#print("lps appended",temp)result=max(temp)returnresult#returnslpsvalueforinputasndefups(n):ref=m.ceil(m.sqrt(n))result=1temp=[]foriinrange(ref,30):#lets find out the smallest prime no greater than refforjinrange(2,i):ifi%j==0:breakelse:temp.append(i)#print("ups appended",temp)result=min(temp)returnresult#main function:arr=list(map(int,input().split()))L=arr[0]R=arr[1]if(Lnotinrange(4,pow(10,18)))or(Rnotinrange(4,pow(10,18)))or((R-L)>pow(10,16)):sys.exit()ans_lst=[]try:foriinrange(L,R+1):lps_val=lps(i)#print("debug lps val=",lps_val)ups_val=ups(i)#print("debug ups val=",ups_val)if(i%lps_val==0andi%ups_val!=0)or(i%ups_val==0andi%lps_val!=0):ans_lst.append(i)print(sum(ans_lst)%1004535809)#print("debug ans_list : ",ans_lst)exceptZeroDivisionError:print("Unexpected glitch")sys.exit()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #234: Semidivisible numbers
You are viewing a single comment's thread. Return to all comments →