Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!

When building the graph, he needs four conditions to be satisfied:

It must be a simple undirected graph, i.e. without multiple (parallel) edges and self-loops.

The number of vertices must be exactly n — a number he selected. This number is not necessarily prime.

The total number of edges must be prime.

The degree (i.e. the number of edges connected to the vertex) of each vertex must be prime.

Below is an example for n=4. The first graph (left one) is invalid as the degree of vertex 2 (and 4) equals to 1, which is not prime. The second graph (middle one) is invalid as the total number of edges is 4, which is not a prime number. The third graph (right one) is a valid answer for n=4.

Note that the graph can be disconnected.

Please help Bob to find any such graph!

Input

The input consists of a single integer n (3≤n≤1000) — the number of vertices.

Output

If there is no graph satisfying the conditions, print a single line containing the integer −1.

Otherwise, first print a line containing a prime number m (2≤m≤n(n−1)2) — the number of edges in the graph. Then, print m lines, the i-th of which containing two integers ui, vi (1≤ui,vi≤n) — meaning that there is an edge between vertices ui and vi. The degree of each vertex must be prime. There must be no multiple (parallel) edges or self-loops.

If there are multiple solutions, you may print any of them.

Note that the graph can be disconnected.

Examples

Input

4

Output

5

1 2

1 3

2 3

2 4

3 4

Input

8

Output

13

1 2

1 3

2 3

1 4

2 4

1 5

2 5

1 6

2 6

1 7

1 8

5 8

7 8

Note

The first example was described in the statement.

In the second example, the degrees of vertices are [7,5,2,2,3,2,2,3]. Each of these numbers is prime. Additionally, the number of edges, 13, is also a prime number, hence both conditions are satisfied.

题意:

让你构造一个n个接点的图,使其边的总个数是质数,每一个节点的度数也是质数。

思路:

利用一个性质 n~n+n/2 这个区间里,必定有一个数是质数。

那么我们可以先把图连成一个圆环,现在边的个数是n。

如果当前边的个数不是质数,那么从1开始,在圆环中加入1与它在圆环中的对面节点1+n/2 连接而成的边。

还不是质数就加入2与对面节点的边,这样可以最多加到 n+n/2个边,根据上面的性质我们可以知道,这个过程中必有边数sum是质数的。

有因为这个过程中每一个节点的度数是2或者3. 所以整体是满足条件的。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
// const int maxn = 1e7+50;
bool noprime[maxn + 50];
vector <int> p;
void getPrime()
{
// 华丽的初始化
memset(noprime, false, sizeof(noprime));
p.clear(); int m = (int)sqrt(maxn + 0.5);
// 优化的埃筛
for (int i = 2; i <= m; i++)
{
if (!noprime[i])
{
for (int j = i * i; j <= maxn; j += i)
{
noprime[j] = true;
}
}
} }
std::vector<pii> v; int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\code_stream\\out.txt","w",stdout);
getPrime();
int n;
gbtb;
cin >> n;
if (!noprime[n])
{
cout << n << endl;
repd(i, 2, n)
{
cout << i << " " << i - 1 << endl;
}
cout << 1 << " " << n << endl;
} else
{
int ans = n;
int t = ans;
while (noprime[t])
{
t++;
}
cout << t << endl;
repd(i, 2, n)
{
cout << i << " " << i - 1 << endl;
}
cout << 1 << " " << n << endl; int id = 1;
while (noprime[ans])
{
ans++;
cout << id << " " << id + n / 2 << endl;
id++;
}
} return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

Codeforces Global Round 4 Prime Graph CodeForces - 1178D (构造,结论)的更多相关文章

  1. Codeforces Global Round 8 C. Even Picture(构造)

    题目链接:https://codeforces.com/contest/1368/problem/C 题意 构造一个只含有灰.白块的网格,要求: 所有灰块为一个连通块 每个灰块与偶数个灰块相邻 恰有 ...

  2. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  3. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  4. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  5. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  6. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  7. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  8. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  9. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

随机推荐

  1. 什么是IntentService?有何优点?

    一.IntentService 简介 IntentService 是 Service 的子类,比普通的 Service 增加了额外的功能.先看 Service 本身存在两个问题:Service 不会专 ...

  2. [pipenv]Warning: Python 3.7 was not found on your system…

    前置条件: 切换到pipfile文件所在目录gotest_official 问题描述: 使用pipenv install创建虚拟环境,报错 wangju@wangju-HP--G4:~/Desktop ...

  3. BurpSuite(二) proxy 模块

      Proxy代理模块作为BurpSuite的核心功能,拦截HTTP/S的代理服务器,作为一个在浏览器和目标应用程序之间的中间人,允许你拦截,查看,修改在两个方向上的原始数据流. Burp 代理允许你 ...

  4. Jmeter(六)事务

    事务是性能测试之必不可少的关注点, Jmeter默认把每一个请求都统计成了一个事务, 但有时候我们根据业务需求, 会把多个操作统计成一个事务, Jmeter当然也考虑到了这个需求, 因此我们可以通过逻 ...

  5. ControlTemplate in WPF —— ItemsControl

    <ItemsControl Margin=" ItemsSource="{Binding Source={StaticResource myTodoList}}"& ...

  6. Python_List对象内置方法详解

    目录 目录 前言 软件环境 列表List 修改列表的元素 插入列表元素 extend 将序列中的元素迭代的附加到list中 insert 在指定的索引号中插入一个元素 删除列表元素 del 删除Lis ...

  7. mysql登录的三种方式

    1.远程登录mysql 先授权:如:grant all on *.* to 'root'@'192.168.81.130' identified by '52033dd';查看是否生效:select ...

  8. 阶段3 2.Spring_09.JdbcTemplate的基本使用_5 JdbcTemplate在spring的ioc中使用

    resources下新建File文件 bean.xml 配置jdbcTemplate 注入DataSource 新建测试方法 复制demo1改个名字叫做demo2 编写Insert的方法

  9. 开源录屏软件Open Broadcaster Software

    Open Broadcaster Software是一款开源录屏软件,功能强大,设计合理,其官方网址是https://obsproject.com/

  10. Dojo入门:初识Dojo

      Dojo的全称是Dojo Toolkit,始创于2004年,是当前各种蓬勃发展的JS工具包中的佼佼者.Dojo 为富互联网应用程序(RIA) 的开发提供了完整的端到端的解决方案,包括核心的 Jav ...