Codeforces Round #257 (Div. 2)E(數論+構造),
E. Jzzhu and Applestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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
26 32 4
input
9
output
39 32 46 8
input
2
output
0
題意:在1到n的數中,找出盡量多的數對,使得每對數的最大公約數>1
思路:先看 1 和大於 n / 2 的素數,這些數可以直接刪掉,因為它們不可能和其它任何數配對 然後對於所有素數 x 且 2 < x <= n / 2,在剩下的未選的數中找出 x 的倍數,看這些數的數量是否為偶數,為偶數可以直接兩兩配對,如果為奇數,則忽略 x*2,將剩下的
數兩兩配對
最後只剩下2的倍數的數沒有被配對,兩兩配對即可