Primes (Gym-102267B)

Problem Description

A prime number is a natural number greater than 1 and has exactly 2 divisors which are 1 and the number itself.

You are given a prime number nn, find any 2 prime numbers aa and bb such that a+b=n or state that no such pair of primes exists.

Input

The input contains a single prime number nn(2≤n≤107).

Output

If there doesn't exist any 2 primes such that their summation is equal to nn then print -1, otherwise print the 2 primes on a single line separated by a space.

Examples

input

5

output

2 3

input

11

output

-1

题意:给出一个质数 n,寻找一个素数对 a、b 使得 a+b=n,若存在素数对 a、b 输出 a、b,否则输出 -1

思路:筛素数后从前向后暴力扫到 n/2 即可,对于每个素数 i,判断 n-i 是否为素数

Source Program

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair
const int MOD = 1E9+7;
const int N = 10000000+5;
const int dx[] = {1,-1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int primes[N],cnt;
bool bPrime[N];
void getPrime(int n) {
    bPrime[0]=true;
    bPrime[1]=true;
    for(int i=2; i<=n; i++) {
        if(!bPrime[i])
            primes[cnt++]=i;
        for(int j=0; j

 

你可能感兴趣的:(#,其它,OJ,#,数论——素性测试)