|
发表于 2020-3-3 20:41:24
|
显示全部楼层
已修改,请测试
- import math
- def fun341(string):
- def getAll(num):
- if num < 4:
- return [1]
- shu = [1]
- low_pow = math.floor(num**(1/2))
- index = 2
- while index < low_pow:
- if num % index==0:
- shu.append(index)
- shu.append(num//index)
- index += 1
- if low_pow**2 == num:
- shu.append(low_pow)
- else:
- if num % index ==0:
- shu.append(low_pow)
- shu.append(num//low_pow)
- shu.sort(reverse = True)
- return shu
- M = len(string)
- if M < 2:
- return False
- possible = getAll(M)
- for eachEle in possible:
- div = M//eachEle
- state = False
- sample = string[0:eachEle]
- for count in range(1,div):
- if string[(count*eachEle):((count+1)*eachEle)] != sample:
- break
- else:
- state = True
- if state == True:
- return True
- else:
- pass
- return False
复制代码 |
|