codeforces-A. Equation

本文介绍了一种算法,用于找到两个复合数之差等于给定正整数n的解决方案。通过预先筛选出一定范围内的质数,算法能快速判断数字是否为复合数,并找出符合条件的复合数对(a, b)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值