用python无脑循环会超时!
所以应该先筛一遍再无脑循环……(大概还存在改进空间)
from math import sqrt
T=int(input())
for I in range(T):
n=int(input())
count=0
while n%2 == 0:
n//=2
count+=1
if count:
print("(2,%d)"%count, end="")
max=int(sqrt(n))+1
for i in range(3, max, 2):
count=0
while n%i==0:
n//=i
count+=1
if count:
print("(%d,%d)"%(i, count), end="")
if n!=1:
print("(%d,1)"%n, end="")
print()
其实不用这么麻烦,比较符合Python风格的思路应该是所有质因数生成列表1,再通过集合为中介去重然后排序保存为列表2,最后用自带的count函数得到列表2内每个元素在列表1中出现的次数
现在最符合Python风格的思路是调用
collections.Counter了(我不确定两年前有没有这个东西可用for example:
最快速度是kangaroo 0.284