题目:
来源:P2029 - [蓝桥杯2022初赛] 数的拆分 - New Online Judge (ecustacm.cn)
实在想不出来什么好办法,暴力求解了。
import math
def f(x):
if x<=2:
return "no"
xq = int(math.sqrt(x))+1
for i in range(1,xq):
if x%i==0:
if g(i):
if g(x//i):
return "yes"
return "no"
def g(x):
if x==1:
return True
xq = int(math.sqrt(x))+1
for i in range(2,xq):
if x%i==0:
xx = x
count = 1
while xx%i==0:
xx = xx//i
count += 1
if xx==1 and count>1:
return True
return False
T = int(input())
for i in range(T):
a = int(input())
print(f(a))
测试:
结果肯定不尽人意,不过纯暴力还跑出来了10%