程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #257 (Div. 2)E(數論+構造)

Codeforces Round #257 (Div. 2)E(數論+構造)

編輯:C++入門知識

Codeforces Round #257 (Div. 2)E(數論+構造)


E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.

Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.

Jzzhu wonders how to get the maximum possible number of groups. Can you help him?

Input

A single integer n (1?≤?n?≤?105), the number of the apples.

Output

The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.

If there are several optimal answers you can print any of them.

Sample test(s) input
6
output
2
6 3
2 4
input
9
output
3
9 3
2 4
6 8
input
2
output
0

題意:在1到n的數中,找出盡量多的數對,使得每對數的最大公約數>1
思路:先看 1 和大於 n / 2 的素數,這些數可以直接刪掉,因為它們不可能和其它任何數配對 然後對於所有素數 x 且 2 < x <= n / 2,在剩下的未選的數中找出 x 的倍數,看這些數的數量是否為偶數,為偶數可以直接兩兩配對,如果為奇數,則忽略 x*2,將剩下的
數兩兩配對
最後只剩下2的倍數的數沒有被配對,兩兩配對即可

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved