Find the full number

Source: Internet
Author: User
Problem

Find the full number.


Ideas
The so-called full number is obtained from the full number of words in Wikipedia:

[Perfect number, also known as perfect number or complete number, is the sum of all its true factors (that is, the approximate number except itself), exactly equal to itself, the exact number cannot be a wedge. For example, the first complete number is 6, which has an approximate number of 1, 2, 3, and 6. Except for its own number of 6, the remaining three numbers are added, and 1 + 2 + 3 = 6, exactly equal to itself. The second complete number is 28, which has an approximate number of 1, 2, 4, 7, 14, and 28. Except for its own 28, the remaining 5 numbers are added together, 1 + 2 + 4 + 7 + 14 = 28, which is exactly equal to itself. The numbers below are 496 and 8128.]

For more information, see this entry.

Therefore, the solution to finding a full number is:
  1. Find all the factors of a number
  2. Verify whether the sum of these factors is equal to this number. If it is equal to, it is the complete number.
Solution (Python)

#! /Usr/bin/ENV Python # Coding: UTF-8 # Find a number of factors def factors (n): # Return [I for I in range (1, n/2 + 1) if n % I = 0] # If you only want to obtain the factor, you can use the above # if it is used together with the complete number below, it is best to use the following. Because less cycles are performed below, 1 must be the factor of any integer. Return [I for I in range (2, n/2 + 1) if n % I = 0] # Find all the full numbers within a certain number of N, that is, within [1, N] (including N) def perfect (n ): # Because 1 is less than 1 in the list of factors obtained from the preceding factors, you must add 1 to the sum of factors. Return [I for I in range (2, n + 1) if (sum (factors (I) + 1) = I] If _ name __= = "_ main _": print perfect (30)

Statement:

This article is a castrated version (the hyperlink is deleted because it cannot be published if so. Why? See the full version. You can enter my GitHub column from the column on the right.

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.