while True:
    n = int(input("输入一个大于 100 的正整数:"))
    if n <= 100:
        print("输入错误!")
    else:
        for i in range(2, int(n/2)+1):
            if n % i == 0:
                print("{}的最小质因数为{}".format(n, i))
                break
        else:
            print("{}是质数".format(n))
            break
输入一个大于 100 的正整数输出这个整数的最小质因数。输入无效数据时要求重新輸入。程序保存到 u2B py。程序执行效果:输入一个大于 100 的正整数:-221输入错误!输入一个正整数:221221的最小质因数为13

原文地址: https://www.cveoy.top/t/topic/dqeu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录