#P9647. [SNCPC2019] To the Park

    ID: 9035 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>2019Special JudgeO2优化陕西素数判断,质数,筛法XCPC

[SNCPC2019] To the Park

题目描述

BaoBao and his (n1)(n-1) classmates are going to the park. For convenience, their teacher DreamGrid has numbered the students from 1 to nn and decides to form the students into some groups, where each group consists of exactly two students.

For some reason, DreamGrid requires that the indices of the two students in the same group should have a common divisor greater than 1. Note that each student can only belong to at most one group, and it's not necessary that every student belongs to a group.

Please help DreamGrid form as many groups as possible.

输入格式

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first and only line contains an integer nn (1n1051 \le n \le 10^5), indicating the number of students.

It's guaranteed that the sum of nn of all test cases will not exceed 10610^6.

输出格式

For each test case output one line. The line first contains an integer kk indicating the number of groups, then 2k2k integers a1,a2,,a2ka_1, a_2, \dots, a_{2k} follow, indicating that student a1a_1 and a2a_2 belong to the same group, student a3a_3 and a4a_4 belong to the same group, ..., student a2k1a_{2k-1} and a2ka_{2k} belong to the same group. The integers in a line are separated by a space. If there are multiple valid answers, you can print any of them.

Please, DO NOT output extra spaces at the end of each line, or your solution may be considered incorrect!

3
1
4
6

0
1 2 4
2 2 4 3 6