Advertisement
nihalshahria

a.cpp

Apr 9th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int tst;
  6.     cin >> tst;
  7.     while (tst--) {
  8.         int n;
  9.         cin >> n;
  10.         cout<<n<<endl;
  11.         if (n == 1) {cout << "1\n1 1\n"; continue;}
  12.         int m[n + 1] = {0};
  13.         vector<int>v[n / 2];
  14.         v[0].push_back(1);
  15.         int x = 0;
  16.         for (int i = 2; i <= n; i+=2)
  17.         {
  18.             m[i]++;
  19.             v[x++].push_back(i);
  20.         }
  21.         for (int i = 3; i <= n; i+=2)
  22.         {
  23.             x = 0;
  24.             if(!m[i]){
  25.                 for (int j = i; j <= n; j+=2*i)
  26.                 {
  27.                     if(!m[j]){
  28.                         if((x+1)%i==0){
  29.                             x++;
  30.                         }
  31.                         if(x<n/2)v[x++].push_back(j),m[j]++;
  32.                         else break;
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.         cout << n / 2 << "\n";
  38.         for (int i = 0; i < n / 2; i++) {
  39.             cout << v[i].size() << " ";
  40.             for (int j = 0; j < v[i].size(); j++)cout << v[i][j] << " ";
  41.             cout << "\n";
  42.         }
  43.         cout<<endl;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement