2632 friends, 2632 friends

Source: Internet
Author: User

2632 friends, 2632 friends
2632 friends

 

Time Limit: 1 s space limit: 128000 KB title level: Gold Title Description Description

Bessie and all other cows wear an RFID serial number card on their ears. Therefore, Farmer John can mechanically calculate their quantity. Many cows have a "cow ". If the sum of the serial numbers of A is exactly the same as the serial number of B, then B is the partner of. Here, the "approx." of a number does not include the number itself.

Some cows have no friends because their numbers are equal to or greater than any other number. Some cows have a "very friend". When two cows are "friends", they are "very friends ". Note that in this question, ignore the situations where you are "very friends.

Given a serial number S (6 ≤ S ≤ 18,000), find the first cow with a "very friend" whose serial number is not smaller than S.

For example, considering the serial number 220, the approximate number is 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, and 110, and is 284. Similarly, about 284 is 1, 2, 4, 71, and 142. Their sum is 220. Therefore, 220 and 284 are very friends.

 

Input description Input Description

Row 1st: A separate integer, namely, the given serial number.

Output description Output Description

Row 1st: two integers, A and B, separated by A space. A Indicates the serial number of the first Dairy Cow whose serial number is not less than S. B indicates the serial number of his "very friend.

Sample Input Sample Input

206

Sample output Sample Output

220 284

Data range and prompt Data Size & Hint

NO

CATEGORY tag Tags click here to expand

Brute force Enumeration

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 int f(int n) 7 { 8     int ans=0; 9     for(int i=1;i<=n-1;i++)10     {11         if(n%i==0)12         {13             ans=ans+i;14         }15     }16     return ans;17 }18 int main()19 {20     int n;21     scanf("%d",&n);22     while(1)23     {24         int p=n;25         n++;26         int sum=f(p);27         int pd=f(sum);28         if(pd==p)29         {30             printf("%d %d",p,sum);31             return 0;32         }33     }34     return 0;35 }

 

Related Article

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.