最大约数

最大约数的计算

 1 def cd(x):
 2     """求一个正整数的除自身外的最大约数"""
 3     count = x // 2
 4     if not(x >= 3):
 5         print('请代入一个大于2的正整数!')
 6     else:
 7         while count-1:
 8             if x % count == 0:
 9                 print('%d的最大约数为:' % x, count)
10                 break
11             count -= 1
12         if count == 1:
13             print('%d为素数' % x)
14 cd(18)  # 18的最大约数为: 9
15 cd(17)  # 17为素数
16 cd(2)  # 请代入一个大于2的正整数!
原文地址:https://www.cnblogs.com/gzj137070928/p/13825582.html