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.
My codes take 10s in Colab and can't pass test case 6. Can anyone help me optimize?
Thanks in advance!
fromitertoolsimportpermutationsdefSubstring_Divisibility(n):### This part takes so much timepermStr=[]foriinpermutations(range(0,n+1)):s=''.join(map(str,i))permStr.append(s)### __________________total=0forsinpermStr:iflen(s[1:4])==3:ifint(s[1:4])%2==0:passelse:continueelse:passiflen(s[2:5])==3:ifint(s[2:5])%3==0:passelse:continueelse:passiflen(s[3:6])==3:ifint(s[3:6])%5==0:passelse:continueelse:passiflen(s[4:7])==3:ifint(s[4:7])%7==0:passelse:continueelse:passiflen(s[5:8])==3:ifint(s[5:8])%11==0:passelse:continueelse:passiflen(s[6:9])==3:ifint(s[6:9])%13==0:passelse:continueelse:passiflen(s[7:10])==3:ifint(s[7:10])%17==0:passelse:continueelse:passtotal+=int(s)returntotalif__name__=='__main__':n=int(input())print(Substring_Divisibility(n))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #43: Sub-string divisibility
You are viewing a single comment's thread. Return to all comments →
My codes take 10s in Colab and can't pass test case 6. Can anyone help me optimize?
Thanks in advance!