A. Equation -------- thinking / enumerate the two approaches +

Let’s call a positive integer composite if it has at least one divisor other than 1 and itself. For example:

the following numbers are composite: 1024, 4, 6, 9;
the following numbers are not composite: 13, 1, 2, 3, 37.
You are given a positive integer n. Find two composite integers a,b such that a−b=n.

It can be proven that solution always exists.

Input
The input contains one integer n (1≤n≤107): the given integer.

Output
Print two composite integers a,b (2≤a,b≤109,a−b=n).

It can be proven, that solution always exists.

If there are several possible solutions, you can print any.

Examples
inputCopy

1
outputCopy
9 8
inputCopy
512
outputCopy
4608 4096

The meaning of problems: two numbers together to find a, b such that ab = n, given n

Analysis:
The first approach: ab = n, then a = b + n, we enumerate b check (b) && check ( b + n), the number of cycles because a certain small primes less.

The second approach: ab = n, then. 3 = A n-, B = 2 n-== with 3N-n-2N =. For a direct output samples, the output for the other A . 3, B 2;

The first:

#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int check(int x)
{
	int i;
	for( i=2;i<=sqrt(x)&&x%i;i++);
	if(i>sqrt(x)) return 0;
	return 1;
}
int main()
{
	cin>>n;
	for(int i=4;;i++)
	{
		if(check(i)&&check(i+n))
		{
			b=i;
			a=i+n;
			break;
		}
 
	}
	cout<<a<<" "<<b<<endl;
 } 

The second:


#include<bits/stdc++.h>
using namespace std;
int n,a,b;
 
int main()
{
	cin>>n;
	if(n==1)
	{
		cout<<9<<" "<<8<<endl;
	}
	else cout<<n*3<<" "<<n*2<<endl;
 } 
Published 309 original articles · won praise 6 · views 5266

Guess you like

Origin blog.csdn.net/qq_43690454/article/details/104074719