My issue
When run on each test case individually, your code appears to be correct. However, when run on the entire test file, it returns a WA. The most common reasons for this are that you do not have a newline after each test case, or you do not reinitialize some variables in each test case.
im getting this while submitting
My code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr(i,a,b) for (int i=a; i<b; i++)
#define loop(x,n) for (int x=0; x<n; x++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
const int N = 1e6+5;
bool isPrime[N];
void precal() {
memset(isPrime,1,sizeof(isPrime));
for (int i=2; i*i<=N; i++) {
if (isPrime[i]) {
for (int j=i*i; j<=N; j+=i) {
isPrime[j] = false;
}
}
}
}
void solve() {
int n;
cin>>n;
if (n%2==1) cout<<1<<" ";
n=n/2;
for (int i=2; i<N; i++) {
if (!isPrime[i]) continue;
cout<<i<<" "<<i<<" ";
n--;
if (n==0) break;
}
cout<<endl;
}
int main() {
fast_io;
cout<<fixed;
cout<<setprecision(10);
precal();
int t;
cin>>t;
loop(x,t) solve();
}
Problem Link: Frequal Practice Coding Problem - CodeChef