Advertisement
Ankit_132

C

Feb 14th, 2024
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int t;
  6.     cin>>t;
  7.    
  8.     vector<int> isPrime(1000001, 1);
  9.    
  10.     for(int i=2; i<=1000000; i++){
  11.         if(!isPrime[i])     continue;
  12.        
  13.         for(int j=2*i; j<=1000000; j+=i)
  14.             isPrime[j] = 0;
  15.     }
  16.    
  17.     while(t--){
  18.         int n;
  19.         cin>>n;
  20.        
  21.         if(n == 1){
  22.             cout<<1<<"\n";
  23.             continue;
  24.         }
  25.         else if(n==2){
  26.             cout<<2<<" "<<2<<"\n";
  27.             continue;
  28.         }
  29.         else if(n==3){
  30.             cout<<1<<" "<<2<<" "<<2<<"\n";
  31.             continue;
  32.         }
  33.        
  34.         cout<<1<<" ";
  35.        
  36.         int done = 1;
  37.        
  38.         if(n%2 == 0){
  39.             done += 3;
  40.             cout<<4<<" "<<4<<" "<<4<<" ";
  41.         }
  42.        
  43.         for(int i=2; done<n; i++){
  44.             if(isPrime[i]){
  45.                 done+=2;
  46.                 cout<<i<<" "<<i<<" ";
  47.             }
  48.         }
  49.        
  50.         cout<<"\n";
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement