欧拉计划21
2016-11-07 11:44
120 查看
昨天困得不得了,忘记做了,还是发现用python写这种东西太方便了,再来试一下。
原题如下:
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
If d(a) = b and d(b) = a, where a ≠ b, then a and b are
an amicable pair and each of a and b are called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
Evaluate the sum of all the amicable numbers under 10000.
代码如下:
结果为: 31626 !!
原题如下:
Amicable numbers
Problem 21
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).If d(a) = b and d(b) = a, where a ≠ b, then a and b are
an amicable pair and each of a and b are called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
Evaluate the sum of all the amicable numbers under 10000.
代码如下:
# -*- coding: UTF-8 -*- def sum1(n): sum = 0 for i in range(1,n/2 + 1): if n%i == 0 : #print i sum+=i #print sum return sum if __name__=="__main__": sum = 0; for i in range(1,10000 + 1): test1 = sum1(i) if( i == sum1(test1) and i != test1): sum += i print sum
结果为: 31626 !!
相关文章推荐
- 欧拉计划 21
- Python实现欧拉计划21题
- 欧拉计划21-23题
- 欧拉计划译文及答案(21-30)
- 在 CentOS 7.x / Fedora 21 上面体验 PHP 7.0
- 面试题21:包含min函数的栈
- 程序员的量化交易之路(21)--Cointrader之Currency货币实体(9)
- Leetcode[21]-Merge Two Sorted Lists
- 飞花的传送门 分类: 比赛 2015-06-18 16:55 21人阅读 评论(0) 收藏
- sql学习笔记(21)-----------触发器
- 【IE bug 解决办法】IE下(IE10及以下)当元素为absolute定位时,点击事件失效的解决办法 分类: ie ie bug ie absolute click 2015-06-26 11:05 21人阅读 评论(0) 收藏
- leetcode-21-Merge Two Sorted Lists
- Solution 21: 子集和问题
- Wormholes 分类: POJ 2015-07-14 20:21 21人阅读 评论(0) 收藏
- 7/21 B 解题报告
- Fedora21启用iptables服务及使用firewalld服务注意事项
- Java IO【21】PrintWriter的学习
- 21-IO流-08-IO流(字符流-练习-复制文本文件_1)
- 27-网络编程-21-网络编程(了解客户端和服务器端原理)
- can't open output file for writing: outfield, errno = 21 for architecture x86_64