Euler program (python) problem 23

Source: Internet
Author: User

Non-abundant Sumsproblem 23

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

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

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

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


Go to the thread for problem the forum.

Python code:

Import Math
Sqrt=math.sqrt


def func1 (x):
M=SQRT (x)
If M-int (m) ==0:
K=1+int (M)
For I in range (2,int (m)):
If x%i==0:
K+=i+int (x/i)
Return K
Else
K=1
For I in range (2,int (m+1)):
If x%i==0:
K+=i+int (x/i)
Return K


dict={}
A=[]
For I in Range (12,28123):
If Func1 (i) >i:
A.append (i)
Dict[i]=1


def func2 (x):
I=0
K=len (a)
While A[i]<x and i<k:
If Dict.get (X-a[i]) ==1:
Return 1
I+=1
return 0
Result=0
For I in Range (1,28123):
If Func2 (i) ==0:
Result+=i


Print (Result)


Time:2s


------------------Wish you good health and good luck
Huadian North Wind Blows
Key Laboratory of cognitive computing and application, School of Computer Science and technology, Tianjin University
No. 92nd, Wei Jin Road, Tianjin
Zip: 300072
Email: [email protected]q.com

Euler program (python) problem 23

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.