THỬ VẬN MAY VỚI ĐOẠN CODE NÀY NHÉ
def la_so_nguyen_to(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def la_so_nguyen_to_sieu(num):
num_str = str(num)
for i in range(1, len(num_str)):
if not la_so_nguyen_to(int(num_str[i:])):
return False
return True
def tim_so_nguyen_to_sieu(N):
so_nguyen_to_sieu = []
bat_dau = 10 ** (N - 1)
ket_thuc = 10 ** N
for num in range(bat_dau, ket_thuc):
if la_so_nguyen_to(num) and la_so_nguyen_to_sieu(num):
so_nguyen_to_sieu.append(num)
return so_nguyen_to_sieu
def main():
with open('SIEUNT.INP', 'r') as f:
N = int(f.readline().strip())
so_nguyen_to_sieu = tim_so_nguyen_to_sieu(N)
with open('SIEUNT.OUT', 'w') as f:
f.write(str(len(so_nguyen_to_sieu)) + '\n')
for so in so_nguyen_to_sieu:
f.write(str(so) + '\n')
if __name__ == "__main__":
main()