咱最开始是这样算得
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Filename: _3.py
from math import sqrt
from math import floor
def isprimer(num):
fac_max = floor(sqrt(num)) + 1
for fac in range(2, fac_max):
if num % fac == 0: return False
return True
def primer(lim):
for n in range(3, lim, 2):
if isprimer(n):
yield n
def main():
num = 600851475143
primer_fac = list(primer(num))
primer_fac_rev = primer_fac[-1::-1]
for pf in primer_fac_rev:
if num % pf == 0:
print("the largest prime factor of %d is %d" % (num, pf))
break
if __name__ == '__main__':
main()