Find 1... All affinity numbers between n

Source: Internet
Author: User


// [10/7/2013 qingezha] Find 1... The number of all affinity between n. // The So-called affinity number, that is, there is a number a and B, the sum of all the true factors of a is equal to B, and the sum of all the true factors of B is equal to a, it is called a and B as a pair of affinity. // For example, the true factor of 220 is: 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, and 284, and the true factor of 284 is: 1, 2, 4, 71, 142, and positive ratio: 220. Therefore, 220 and 284 are a pair of affinity numbers. // If the true factor of j is set to sum [j], then j can be divisible by all the factors and sum [j]. The possible division is the key void print_Affsum (int n) {if (n <= 0) return; int * sum = new int [n + 1]; for (int I = 1; I <n + 1; ++ I) sum [I] = 1; // All affinity numbers have the factor 1for (int I = 2; I <n/2; ++ I) // I as the factor, therefore, the maximum value can only be n/2 {for (int j = 2 * I; j <n + 1; j + = I). // j indicates that I can be divisible, so the increment is I {sum [j] + = I;} int I = 1; while (I <n + 1) {if (sum [I] <n + 1 & I = sum [sum [I]) // do not forget to check the value of sum [I, because sum [sum [I] may cross-border cout <I <"" <sum [I] <endl; ++ I;} delete [] sum ;}


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.