Codeforces Round #257 (Div. 2) E (number theory + structure)

Source: Internet
Author: User
Tags greatest common divisor

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? ≤?N? ≤? (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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.