一、内容
Let's call a positive integer composite if it has at least one divisor other than 1and itself. For example: the following numbers are composite: 1024, 4, 6, 9;the following numbers are not composite: 13, 1, 2, 3, 37You 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.
Input
1
Output
9 8
二、思路
- 线性筛法暴力处理一下
三、代码
#include <cstdio>
const int N = 1e7 + 5000;
int n, cnt, pri[N + 5];
bool v[N + 5];
void init() {
v[1] = true;
for (int i = 2; i <= N; i++) {
if (!v[i]) pri[cnt++] = i;
for (int j = 0; pri[j] <= N / i; j++) {
v[i * pri[j]] = true;
if (i % pri[j] == 0) break;
}
}
}
int main() {
scanf("%d", &n);
init();
for (int i = 4; ; i++) {
if (v[i] && v[i + n]) {
printf("%d %d", i + n, i);
break;
}
}
return 0;
}