1758B - XOR = Average - CodeForces Solution


constructive algorithms

Please click on ads to support us..

Python Code:

t = int(input())
for i in range(t):
    n = int(input()) 
    if(n%2==1):
        for i in range(n):
            print(n,end =" ")
        print() 
    else:
        print(1,3,end=" ") 
        for i in range(n-2):
            print(2,end = " ") 
        print()

C++ Code:

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>  //  --> PBDS
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long;
using ull = unsigned long long;

const int mod = 1e9+7;
const int mod2 = 998244353;

#define what_is(x) cerr << #x << " is " << x << endl;
#define prec(n) fixed << setprecision(n)
#define inf (ll)1e18
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define trail(x) __builtin_ctzll(x) // -> number of trailing zeros
#define pll pair<ll,ll>
#define mp make_pair
#define fr first
#define sc second
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define nl "\n"
#define lb lower_bound
#define ub upper_bound
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> // (*s.find_by_order)(s.order_of_key)(insert,erase,size,lb,ub)
/*------------------------------------------------------------------------------------------------------------*/
ll countSetBits(ll n) { ll count = 0; while (n) { count += n & 1; n >>= 1;} return count; }
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
bool powerOfTwo(ll n) { return n && (!(n & (n-1))); }
void toLower(string& s) { transform(s.begin(), s.end(), s.begin(), ::tolower); }
void toUpper(string& s) { transform(s.begin(), s.end(), s.begin(), ::toupper); }
/*************************************************************************************************************/

vector<ll> primes; // all the primes till (1e7)
vector<bool> seive(1e7+10,true);
void createSeive()
{
    seive[0] = seive[1] = false;
    for(int i=2;i*i<=int(1e7);++i){
        if(seive[i])
        {
            for(int j=i*i;j<=int(1e7);j+=i) seive[j]=false;
        }
    }
    for(int i=0;i<seive.size();++i) if(seive[i]) primes.pb(i);
}

ll binexpo(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
        res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}
ll modInverse(ll n, ll mod)  // euler's totient --> eulers theorm --> fermat's
{
    return binexpo(n, mod - 2, mod);  // MMI of A is --> A^(mod-2) % mod
}
vector<ll>fact;
void factorial(ll n,ll mod)
{
    fact.resize(n+1);
    fact[0]=1;
    for(int i=1;i<=n;++i) fact[i] = (fact[i-1]*i) % mod;
}
ll nCrModPFermat(ll n, ll r, ll mod)  // nCr % mod calculation
{
    fact.resize(n+1);
    if (n < r) return 0;  // If n<r, then nCr should return 0
    if (r == 0) return 1;  // Base case
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % mod;
    return (fact[n] * modInverse(fact[r], mod) % mod* modInverse(fact[n - r], mod) % mod)% mod;
}

bool isPrime(ll n)
{
    // Corner case
    if (n <= 1) return false;
    // Check from 2 to square root of n
    for (int i = 2; i*i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

class DSU{
    vector<ll> parent;
    vector<ll> subtree_size;
    ll N;
public:
    DSU(ll n){
        N = n;
        parent = vector<ll>(n+1, 0);
        subtree_size = vector<ll>(n+1, 1);

        for(int i=1; i<=n; i++) parent[i] = i;
    }

    ll findRoot(ll u){
        while(u != parent[u]){
            parent[u] = parent[parent[u]]; //Path compression
            u = parent[u];
        }

        return u;
    }

    bool combine(ll u, ll v){
        ll ru = findRoot(u); // root of u
        ll rv = findRoot(v); // root of v

        if(ru == rv) return false; // no need to join(same group)
        
        // small to large merging --> (union by rank or size)
        if(subtree_size[ru] > subtree_size[rv]){
            parent[rv] = ru;
            subtree_size[ru] += subtree_size[rv];
        } else{
            parent[ru] = rv;
            subtree_size[rv] += subtree_size[ru];
        }
        return true;
    }
};
/********************* KMP (pattern matching)*********************/
ll kmp(string String, string pattern) {
  ll i = 0, j = 0, m = pattern.length(), n = String.length();
  pattern = '#' + pattern; //just shifting the pattern indices by 1
  vector < ll > piTable(m + 1, 0);
  for (int i = 2; i <= m; i++) {
    while (j <= m && pattern[j + 1] == pattern[i])
      piTable[i++] = ++j;
    j = 0;
  }
  j = 0;
  for (int i = 0; i < n; i++) {
    if (pattern[j + 1] != String[i]) {
      while (j != 0 && pattern[j + 1] != String[i])
        j = piTable[j];
    }
    j++;
    if (j == m) return (i - m + 1); // index of the pattern in the string
  }
  return -1; // not found
}
/******************************************************************/
void precompute()
{
    
}

void solve()
{
    
    int n; cin >> n;
    if(n&1)
    {
        for(int i=0;i<n;++i)
        {
            cout << 69 << " ";
        }
        cout << nl;
    }else{
        for (int i = 0; i < n-2; ++i)
        {
            cout << 4 << " ";
        }
        cout << "2 6";
        cout << nl;
    }
    
    
}

signed main() {
    
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // fast io
    precompute();
    int tc = 1;
    cin >> tc;
    for(int t=1;t<=tc;++t)
    {
        //cout << "Case #" << i << ": ";
        solve();
    } 
return 0;  
}
//end
 	        	 	 	 	   		 			    	


Comments

Submit
0 Comments
More Questions

1133C - Balanced Team
1704A - Two 0-1 Sequences
1467A - Wizard of Orz
1714E - Add Modulo 10
1714A - Everyone Loves to Sleep
764A - Taymyr is calling you
1714B - Remove Prefix
1264F - Beautiful Fibonacci Problem
52A - 123-sequence
1543A - Exciting Bets
1714D - Color with Occurrences
215B - Olympic Medal
1445A - Array Rearrangment
1351A - A+B (Trial Problem)
935B - Fafa and the Gates
1291A - Even But Not Even
1269A - Equation
441A - Valera and Antique Items
1702C - Train and Queries
816B - Karen and Coffee
838D - Airplane Arrangements
148B - Escape
847G - University Classes
1110A - Parity
1215B - The Number of Products
604C - Alternative Thinking
1204C - Anna Svyatoslav and Maps
322A - Ciel and Dancing
1689B - Mystic Permutation
1711B - Party