結果
| 問題 | No.1665 quotient replace | 
| コンテスト | |
| ユーザー |  Kude | 
| 提出日時 | 2021-09-03 21:36:19 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2,327 ms / 3,000 ms | 
| コード長 | 2,582 bytes | 
| コンパイル時間 | 4,289 ms | 
| コンパイル使用メモリ | 254,796 KB | 
| 最終ジャッジ日時 | 2025-01-24 05:02:40 | 
| ジャッジサーバーID (参考情報) | judge3 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 41 | 
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
std::pair<std::vector<int>,std::vector<int>> primes_lpf(const int n) {
    std::pair<std::vector<int>,std::vector<int>> rv;
    std::vector<int>& primes = rv.first;
    std::vector<int>& lpf = rv.second;
    primes.reserve(n / 10);
    lpf.resize(n + 1);
    for(int i = 2; i <= n; i += 2) lpf[i] = 2;
    for(int i = 3; i <= n; i += 6) lpf[i] = 3;
    if (2 <= n) primes.push_back(2);
    if (3 <= n) primes.push_back(3);
    // 5 * x <= n, x <= floor(n / 5)
    const int n5 = n / 5;
    int x = 5;
    bool one_mod6 = false;
    // x_1 <= n5, x_2 = x_1 + 2 <= n5 + 2 <= n
    for(; x <= n5; one_mod6 = !one_mod6, x += (one_mod6 ? 2 : 4)) {
        if (lpf[x] == 0) {
            lpf[x] = x;
            primes.push_back(x);
        }
        int px = lpf[x];
        for(int i = 2;; ++i) {
            int q = primes[i];
            int y = q * x;
            if (y > n) break;
            lpf[y] = q;
            if (q == px) break;
        }
    }
    for(; x <= n; one_mod6 = !one_mod6, x += (one_mod6 ? 2 : 4)) {
        if (lpf[x] == 0) {
            lpf[x] = x;
            primes.push_back(x);
        }
    }
    return rv;
}
auto [primes, lpf] = primes_lpf(1000000);
// global variable lpf must be defined
std::vector<std::pair<int,int>> factorize(int n) {
    std::vector<std::pair<int,int>> fs;
    while(n > 1) {
        int p = lpf[n];
        int cnt = 0;
        do {n /= p; cnt++;} while(n % p == 0);
        fs.emplace_back(p, cnt);
    }
    return fs;
}
int g[1000001];
VI dests[1000001];
bool table[1000001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i = 1; i <= 1000000; i++) {
        for(int x: dests[i]) table[x] = true;
        int t = 0;
        while(table[t]) t++;
        g[i] = t;
        for(int x: dests[i]) table[x] = false;
        for(int j = i + i; j <= 1000000; j += i) dests[j].push_back(t);
    }
    int n;
    cin >> n;
    int gr = 0;
    rep(_, n) {
        int x;
        cin >> x;
        gr ^= g[x];
    }
    cout << (gr ? "white" : "black") << endl;
}
            
            
            
        