Seeking to close less than the number of 20,000. The so-called logarithmic close, i.e., A in addition to an integer factor all outside itself equal to the sum of B, B in addition to outer integer itself all factors equals A.
Requirements: a write function to find an integer number of itself in addition to all the factors of the sum of the outer (note 1 is any integer factor).
format requirement:
The user input positive integer n represents the n-th desired intimate logarithm (logarithm of close arranged in numerical increments). For example, if a user enters "1", the program outputs "220 284" denotes: the number of the first pair is close to 220 and 284 (first output value of the smaller number, then a space, then the output value of the bigger number) . Submitting the code can not have other unwanted cin and cout statement
results are as follows:
Input: 1
Output: 220,284
#include <iostream>
#include <cmath>
using namespace std;
int logarithm(int);
int main()
{
int n, k=0;
cin>>n;
for(int a=200; a<=20000; a++)
{
int b = logarithm(a);
if(logarithm(b)==a && a<b)
{
k++;
if(k == n)
cout<<a<<" "<<b;
}
}
return 0;
}
int logarithm(int x)
{
int sum=0;
for(int i=1; i<=sqrt(x); i++)
{
if(x%i == 0)
{
int k = x/i;
sum += i+k;
if(k == i || k == x)
sum = sum - k;
}
}
return sum;
}