projecteuler---->problem=23----Non-abundant sums

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.

A number n is called deficient if the sum of its proper divisors is less than
n and it is called abundant if this sum exceeds n.

As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two
abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.

Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

翻译;

完全数,就是能表示成其小于自身的所有因数的和的正整数。例如,28可表示成1 + 2 + 4 + 7 + 14 = 28,故28是一个完全数。

一个正整数n,若其小于自身的所有因数的和小于n则n是不足数,若大于则n为充足数。

12是最小的充足数,1 + 2 + 3 + 4 + 6 = 16。能表示成两个充足数的和的最小正整数是24。经数学分析,可知任一超过28123的整数都能写成两个充足数的和。

请求出所有不能表示成两个充足数的和的正整数的和。

代码:

def getSum(a):
    s=0
    for i in range(1,a/2+1):
        if a%i==0:
            s+=i
    return s

a,count=[0 for i in range(28124)],0
b=[0 for i in range(28124)]
for i in range(1,28124):
    s=getSum(i)
    if (s>i):
        a[count]=i
        count+=1
print count
for i in range(0,count):
    for j in range(i,count):
        tmp=a[i]+a[j]
        if tmp<28124:
            b[tmp]=1

test=0
for i in range(1,28124):
    if b[i]==0:
        test+=i
print test         

projecteuler---->problem=23----Non-abundant sums

时间: 2024-11-05 20:25:59

projecteuler---->problem=23----Non-abundant sums的相关文章

欧拉计划(python) problem 23

Non-abundant sums Problem 23 A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect nu

Project Euler:Problem 23 Non-abundant sums

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is called de

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

leetcode problem :23. Merge k Sorted Lists

class Solution { public: ListNode* mergeKLists(vector<ListNode*>& lists) { ListNode* head = NULL; ListNode* current = NULL; for (int i = 0; i < lists.size(); ++i){ if (!lists[i]){ lists.erase(lists.begin()+i); --i; } } while (lists.size()){ i

Project Eluer - 23

Non-abundant sums Problem 23 A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect nu

D - K Smallest Sums(多路归并+贪心)

Problem K K Smallest Sums You're given k arrays, each array has k integers. There are kk ways to pick exactly one element in each array and calculate the sum of the integers. Your task is to find the k smallest sums among them. Input There will be se

(DS 《算法竞赛入门经典》)UVA 11997 K Smallest Sums

题目大意:有k个数组,每个数组选取一个数,组成k^k个数.在这k^k个数中选择最小的前k个数 解题思路: 1.如果只有k个数组,那么最后得到的最小的前k个数应该可以由前两个数组得到的最小k个数与第三个数组 按规则运算后得到. 2.如果每个数组只有3个数.那么前两个数组(a:(a0,a1,a2)    b:(b0,b1,b2,a与b数组都已经有序)运算后有的结果矩阵如下: a0+b0,a0+b1,a0+b2 a1+b0,a1+b1,a1+b2 a2+b0,a2+b1,a2+b2 在这个矩阵中,a0

欧拉计划21-23题

21.Amicable numbers 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

我对于搜索算法的慢慢摸索

高中的时候好像什么都没学会的样子,提到搜索脑子里云里雾里一般.还能怎么着,练呗. 找到了一道dfs基础题,http://poj.org/problem?id=1190 果然是完全没有思路,参照大佬的题解,弄懂了大佬的思路. 1 //生日蛋糕 2 //poj 1190 3 #include<stdio.h> 4 #include<math.h> 5 #define INF 1000000 6 int mins[21],minv[21];//从第一层到第i层的最小体积minv和最小面积

面试中常见算法1

Problem 1 : Is it a loop ? (判断链表是否有环?) Assume that wehave a head pointer to a link-list. Also assumethat we know the list is single-linked. Can you come up an algorithm to checkwhether this link list includes a loop by using O(n) time and O(1) space