2007年12月18日 星期二 23:47
ÓиöÎÊÌâ for s in range(101,201): num=[] for m in range(1,s+1): i = s / m if i== int(i): num.append(i) else: print "no" if len(num)>=2: print s Õâ¸öÊÇÎÒдµÄ µ«¼ì²âʧ°ÜÁË Çë´ó¼Ò°ïÎÒ¿´¿´ -- deSign thE fuTure -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071218/6e5b33c1/attachment-0001.htm
2007年12月19日 星期三 00:44
pythonÀïÃæÁ½¸öÕûÊýÏà³ýµÃµ½µÄÊÇÕûÊý£¬ËùÒÔ"i = s / m"Ó¦¸Ã¸ÄΪ"i = float(s) / m"¡£ÁíÍâÁ½¸örangeдµÃÓÐÎÊÌ⡣ǰÃæµÄÓ¦¸ÃÊÇrange(100, 201)£¬ºóÃæµÄÓ¦¸ÃÊÇrange(1, s)¡£ÕâÑùÎÒÕâÀïÊä³ö½á¹û¾ÍÕýÈ·ÁË¡£ ÔÚ07-12-18£¬free. won <freefis在gmail.com> дµÀ£º > > ÓиöÎÊÌâ > for s in range(101,201): > num=[] > for m in range(1,s+1): > i = s / m > if i== int(i): > num.append(i) > else: > print "no" > if len(num)>=2: print s > > Õâ¸öÊÇÎÒдµÄ µ«¼ì²âʧ°ÜÁË Çë´ó¼Ò°ïÎÒ¿´¿´ > -- > deSign thE fuTure > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071219/70afa664/attachment-0001.html
2007年12月19日 星期三 09:41
改进一下 for s in range(101,201): num=[] for m in range(2,s/2): #只需要判断2到s/2范围内的即可,这样可节约大量计算 if s % m == 0: #整除用余数判断效率高一些,也更自然一些 num.append(s/m) else: print "no" if len(num)>=2: print s 在07-12-18,free. won <freefis at gmail.com> 写道: > > 有个问题 > for s in range(101,201): > num=[] > for m in range(1,s+1): > i = s / m > if i== int(i): > num.append(i) > else: > print "no" > if len(num)>=2: print s > > 这个是我写的 但检测失败了 请大家帮我看看 > <http://python.cn/mailman/listinfo/python-chinese> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20071219/6c9c4126/attachment.htm
2007年12月19日 星期三 10:16
On Dec 18, 2007 11:47 PM, free. won <freefis在gmail.com> wrote: > 有个问题 > for s in range(101,201): > num=[] > for m in range(1,s+1): > i = s / m > if i== int(i): > num.append(i) > else: > print "no" > if len(num)>=2: print s > > 这个是我写的 但检测失败了 请大家帮我看看 import math for s in range(101,201): for m in range(2,int(math.sqrt(s))+1): if s % m == 0: break else: print s -- Best Regards, Leo Jay
2007年12月19日 星期三 11:21
¸Ä½øµÄ¸ßЧËã·¨ÊÇÕýµÀ£¬ÎÒÖ»ÊǾÀÕýÁËÓï·¨ÉϵĴíÎóºÇºÇ¡£ 2007/12/19, Leo Jay <python.leojay在gmail.com>: > > On Dec 18, 2007 11:47 PM, free. won <freefis在gmail.com> wrote: > > ÓиöÎÊÌâ > > for s in range(101,201): > > num=[] > > for m in range(1,s+1): > > i = s / m > > if i== int(i): > > num.append(i) > > else: > > print "no" > > if len(num)>=2: print s > > > > Õâ¸öÊÇÎÒдµÄ µ«¼ì²âʧ°ÜÁË Çë´ó¼Ò°ïÎÒ¿´¿´ > > > import math > > for s in range(101,201): > for m in range(2,int(math.sqrt(s))+1): > if s % m == 0: > break > else: > print s > > -- > Best Regards, > Leo Jay > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071219/b9e85b04/attachment.htm
2007年12月19日 星期三 11:38
def getPrimeTable(n): i=2 pl=[] while i<=n: isPrime = True for x in pl: if i%x == 0: isPrime = False break if isPrime: pl.append(i) i+=1 return pl ¸øÒ»¸öͨÓõĿ´ÏÂ...ËäÈ»ºÍÄãÕâ¸ö²»Ì«ÍêÈ«Ò»Ñù. Ï£Íû¿ÉÒÔ¸øµã˼·. ÔÚ07-12-19£¬Li Qingfeng <liqfemail在gmail.com> дµÀ£º > > ¸Ä½øµÄ¸ßЧËã·¨ÊÇÕýµÀ£¬ÎÒÖ»ÊǾÀÕýÁËÓï·¨ÉϵĴíÎóºÇºÇ¡£ > > 2007/12/19, Leo Jay <python.leojay在gmail.com>: > > > > On Dec 18, 2007 11:47 PM, free. won <freefis在gmail.com> wrote: > > > ÓиöÎÊÌâ > > > for s in range(101,201): > > > num=[] > > > for m in range(1,s+1): > > > i = s / m > > > if i== int(i): > > > num.append(i) > > > else: > > > print "no" > > > if len(num)>=2: print s > > > > > > Õâ¸öÊÇÎÒдµÄ µ«¼ì²âʧ°ÜÁË Çë´ó¼Ò°ïÎÒ¿´¿´ > > > > > > import math > > > > for s in range(101,201): > > for m in range(2,int(math.sqrt(s))+1): > > if s % m == 0: > > break > > else: > > print s > > > > -- > > Best Regards, > > Leo Jay > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- ¶«×Ó! ŬÁ¦×öºÃÿһ¼þÊÂ!!! -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071219/b93154c7/attachment.htm
2007年12月19日 星期三 12:10
呵呵,有道理,应该是取开方 把int(math.sqrt(s))+1)改成math.ceil(math.sqrt(s))就更合理啦^_^ 2007/12/19, Leo Jay <python.leojay at gmail.com>: > > > import math > > for s in range(101,201): > for m in range(2,int(math.sqrt(s))+1): > if s % m == 0: > break > else: > print s > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20071219/80bb9d28/attachment.html
2007年12月24日 星期一 10:07
在小尺度数以内搜索质数(具体多少没试过6位数字以内吧),递归方法很快。 大尺度情况下搜索质数,如达到python的整形能表达的最大值,要用到特殊方法进行计算了。曾经编过一个,修改了迭代器,算出了2E多个质数。。。 在07-12-19,amingsc <amingsc在gmail.com> 写道: > > 呵呵,有道理,应该是取开方 > 把int(math.sqrt(s))+1)改成math.ceil(math.sqrt(s))就更合理啦^_^ > > 2007/12/19, Leo Jay <python.leojay在gmail.com>: > > > > > > import math > > > > for s in range(101,201): > > for m in range(2,int(math.sqrt(s))+1): > > if s % m == 0: > > break > > else: > > print s > > > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- 一个HTML附件被移除... URL: http://python.cn/pipermail/python-chinese/attachments/20071224/99ce26cb/attachment.htm
2007年12月24日 星期一 18:32
лл¸÷λÁË¡£ µÚÒ»´Î·¢ÎÊÌâ ÄÇô¶àÈË°ïÖú¡£ ¸Ð¶¯¡« ÔÚ07-12-24£¬yuan xuan <xuanyuan14.leo在gmail.com> дµÀ£º > > ÔÚС³ß¶ÈÊýÒÔÄÚËÑË÷ÖÊÊý£¨¾ßÌå¶àÉÙûÊÔ¹ý6λÊý×ÖÒÔÄÚ°É£©£¬µÝ¹é·½·¨ºÜ¿ì¡£ > > ´ó³ß¶ÈÇé¿öÏÂËÑË÷ÖÊÊý£¬Èç´ïµ½pythonµÄÕûÐÎÄܱí´ïµÄ×î´óÖµ£¬ÒªÓõ½ÌØÊâ·½·¨½øÐмÆËãÁË¡£Ôø¾±à¹ýÒ»¸ö£¬ÐÞ¸ÄÁ˵ü´úÆ÷£¬Ëã³öÁË2E¶à¸öÖÊÊý¡£¡£¡£ > > ÔÚ07-12-19£¬amingsc < amingsc在gmail.com> дµÀ£º > > > > ºÇºÇ£¬ÓеÀÀí£¬Ó¦¸ÃÊÇÈ¡¿ª·½ > > °Ñint(math.sqrt(s))+1)¸Ä³Émath.ceil(math.sqrt (s))¾Í¸üºÏÀíÀ²^_^ > > > > 2007/12/19, Leo Jay <python.leojay在gmail.com >: > > > > > > > > > import math > > > > > > for s in range(101,201): > > > for m in range(2,int(math.sqrt(s))+1): > > > if s % m == 0: > > > break > > > else: > > > print s > > > > > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- deSign thE fuTure -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071224/4f1e890e/attachment.htm
Zeuux © 2024
京ICP备05028076号