O(m*n) Python3 Solution
\nIn my code, the first function defined what "contain" is and the second function is to find maximum m.\n\nWe know that, in the best case:\n    S1 = s1n1\n    
\nIn my code, the first function defined what "contain" is and the second function is to find maximum m.\n\nWe know that, in the best case:\n    S1 = s1*n1\n    S2 = s2*n2\nWe compute the quotient of lengths of S1 and S2, which is M in the code and M is the best repetition we can get.\nAnd count down from M, return the repetition as long as S1 contains S2.\n\nFor example:\nif the length of S1 is 12, and S2\'s length is 3, the largest (best) m could be 4, or less, \nif 4*S2 can\'t meet the condition, then let m be 3, and check again.\nThis way, we only check 4 times at worst.\n\n```\ndef Contain(L1,L2):\n    for i in range(len(L2)):\n        if L2[i] in L1:\n            L1 = L1[L1.index(L2[i]):]\n        else:\n            return False\n    return True\n\ndef getMaxRepetitions(s1,n1,s2,n2):\n    S1 = s1*n1\n    S2 = s2*n2\n    M = int(len(S1)//len(S2))\n    for m in range(M,1,-1):\n        if Contain(S1,S2*m):\n            return m\n\n\n```\n\n ===================================================== 4/22/2019 Update =====================================================\n\nThanks to @luzi82 for pointing out my problem.\nIn this part, if the range is from M to 1, it\'ll exclude m=1\n```\nfor m in range(M,1,-1):\n        if Contain(S1,S2*m):\n            return m\n```\nI changed it into:\n```\nfor m in range(M,0,-1):\n        if Contain(S1,S2*m):\n            return m\n```\nAnd it worked for the cases of 1 repetition.\n\nAnd as for the case:\ns1="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"\nn1=1000000\nRunning time is up to 48s \nThe main part slowing things down is the calculation: S1 = s1n1\nWhen n1 is really large, this algorithm could be really slow.\n\nWhat\'s sarcastic is that I used the title \'fast solution\' when I first posted this answer.\nI\'ll keep updated on this section with better solution. \nAnd you\'re very welcome to give me some feedback and to let me know how to improve the algorithm. \n\n
['Python', 'Python3']