python中求素数(质数)的方法:

基本方法:
方法1: [x for x in range(1,a) if not [y for y in range(2,int(x/2)+1) if x%y==0]]
改进方法:
方法2: [x for x in range(1,a) if not [y for y in range(2,round(x**0.5)+1) if x%y==0]]
方法3: [x for x in range(1,a) if not [y for y in range(2,round(math.sqrt(x))+1) if x%y==0]]
方法2最高效,方法3调用math模块,降低了效率,大家有更好的方法,请留言大家讨论

Peterson, 28, predicts he will relate well to his future students Podcasts buyessayonline.ninja/ buy essay papers online cheap are a total sanity saver if you commute

标签: ,
本文连接地址: http://www.fresker.com/archives/503 (转载注明出处)

回复

目前暂无评论

Sorry, 评论已关闭.