牛客华为机试HJ60
作者:互联网
1. 问题描述
2. Solution
1、思路
从中间n//2向两侧遍历,找到第一组素数和即可。
2、实现
import sys
if sys.platform != "linux":
file_in = open("input/HJ60.txt")
sys.stdin = file_in
def is_prime(n):
i = 2
while i * i <= n:
if n % i == 0:
return False
i += 1
return True
def solve(n):
i = n // 2
j = n - i
while not is_prime(i) or not is_prime(j):
i += 1
j -= 1
print(j)
print(n - j)
for line in sys.stdin:
n = int(line.strip())
solve(n)
标签:原题,传送门,sys,牛客,HJ60,file,linux,机试 来源: https://www.cnblogs.com/junstat/p/16172588.html