Codeforces Round #257 (Div. 2) E (number theory + structure ),
E. Jzzhu and Applestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Jzzhu has pickedNApples from his big apple tree. All the apples are numbered from 1N. Now he wants to have them to an apple store.
Jzzhu will pack his apples into groups and then 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 integerN(1 digit ≤ DigitNLimit ≤ limit 105), the number of the apples.
Output
The first line must contain a single integerM, Representing the maximum number of groups he can get. Each of the nextMLines 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
In the numbers from 1 to n, find as many number pairs as possible, so that the maximum common number of each logarithm is greater than 1.
Idea: first look at the prime numbers 1 and greater than n/2. These numbers can be deleted directly, because they cannot be paired with any other number and then find a multiple of x in the unselected number for all prime numbers x and 2 <x <= n/2, check whether the number of these numbers is an even number. If the number is an even number, the pairs can be directly paired. If the number is an odd number, ignore x * 2 and
Pairing
At last, only the number of multiples of 2 is not paired. You can pair them with each other.