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

來源:互聯網
上載者:User

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的倍數的數沒有被配對,兩兩配對即可



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.