codeforces-A. Ecuación

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
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
const ll maxv=1e7+10; 
ll is_prime[maxv];
void sieve(ll n){
    //ll t=0;
    for(ll i=0;i<=n;i++){//将初值均赋值为true
        is_prime[i]=true;
    }
    for(ll i=2;i<=n;i++){
        if(is_prime[i]){
            //t++;
            for(ll j=2*i;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
	//cout<<t<<endl; 
}
int main(){
	sieve(maxv);
	ll n=0;
	cin>>n;
	ll a=0;
	for(ll b=1;b<=1e7;b++){
		a=b+n;
		if(!is_prime[a] && !is_prime[b]){
			cout<<a<<" "<<b;
			break;
		}
	}
	return 0;
}

 

Publicado 71 artículos originales · ganado elogios 22 · vistas 6035

Supongo que te gusta

Origin blog.csdn.net/Kevin__Coder/article/details/103647777
Recomendado
Clasificación