赞
踩
输入一个正偶数,将其分解成两个素数之和
def demo(n): def IsPrime(p): if p == 2: return True if p%2 == 0: return False for i in range(3, int(p**0.5)+1, 2): if p%i==0: return False return True if isinstance(n, int) and n>0 and n%2==0: for i in range(2, n//2+1): if IsPrime(i) and IsPrime(n-i): print(i, '+', n-i, '=', n) n=int(input("please input n:")) print(demo(n))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。