結果

問題 No.1946 ロッカーの問題
ユーザー moharan627moharan627
提出日時 2022-05-20 22:51:13
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 3,000 ms
コード長 4,042 bytes
コンパイル時間 6,773 ms
コンパイル使用メモリ 314,352 KB
実行使用メモリ 9,204 KB
最終ジャッジ日時 2023-10-20 13:42:06
合計ジャッジ時間 8,392 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,348 KB
testcase_01 AC 6 ms
4,348 KB
testcase_02 AC 8 ms
7,620 KB
testcase_03 AC 126 ms
9,204 KB
testcase_04 AC 8 ms
7,620 KB
testcase_05 AC 10 ms
6,828 KB
testcase_06 AC 11 ms
7,092 KB
testcase_07 AC 9 ms
6,300 KB
testcase_08 AC 43 ms
6,036 KB
testcase_09 AC 114 ms
8,676 KB
testcase_10 AC 96 ms
7,884 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 25 ms
6,036 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,716 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 65 ms
6,564 KB
testcase_18 AC 131 ms
8,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#if !__INCLUDE_LEVEL__

#include __FILE__
struct Eratosthenes {
    // テーブル
    vector<bool> isprime;

    // 整数 i を割り切る最小の素数
    vector<int> minfactor;

    // コンストラクタで篩を回す
    Eratosthenes(int N) : isprime(N+1, true),
                          minfactor(N+1, -1) {
        // 1 は予めふるい落としておく
        isprime[1] = false;
        minfactor[1] = 1;

        // 篩
        for (int p = 2; p <= N; ++p) {
            // すでに合成数であるものはスキップする
            if (!isprime[p]) continue;

            // p についての情報更新
            minfactor[p] = p;

            // p 以外の p の倍数から素数ラベルを剥奪
            for (int q = p * 2; q <= N; q += p) {
                // q は合成数なのでふるい落とす
                isprime[q] = false;

                // q は p で割り切れる旨を更新
                if (minfactor[q] == -1) minfactor[q] = p;
            }
        }
        
    }

    // 高速素因数分解
    // pair (素因子, 指数) の vector を返す
    vector<pair<int,int>> factorize(int n) {
        vector<pair<int,int>> res;
        while (n > 1) {
            int p = minfactor[n];
            int exp = 0;

            // n で割り切れる限り割る
            while (minfactor[n] == p) {
                n /= p;
                ++exp;
            }
            res.emplace_back(p, exp);
        }
        return res;
    }
        // 高速約数列挙
    vector<int> divisors(int n) {
        vector<int> res({1});

        // n を素因数分解 (メンバ関数使用)
        auto pf = factorize(n);

        // 約数列挙
        for (auto p : pf) {
            int s = (int)res.size();
            for (int i = 0; i < s; ++i) {
                int v = 1;
                for (int j = 0; j < p.second; ++j) {
                    v *= p.first;
                    res.push_back(res[i] * v);
                }
            }
        }
        sort(all(res));
        return res;
    }  
};
int main()
{
    Eratosthenes er(250000);
    
    ll N,M;cin >>N >> M;
    vl A(M);rep(i,M)cin >> A[i];
    vl Last(N+1,0);
    fore(a,A)Last[a]=1;
    vl L(N+1,0);
    ll Ans = 0;
    rrep(n,N){
        if(n==0)continue;
        if(Last[n]==L[n]){
            Ans+=1;
        }
        else{
            auto div = er.divisors(n);
            fore(d,div){
                L[d]+=1;
                L[d]%=2;
            }
        }
    }
    cout << Ans << endl;
}

#else

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define range(i, m, n) for(int i = m; i < n; i++)
#define fore(i,a) for(auto &i:a)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sum(v) accumulate(all(v),0)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
const ll INF = 1e16;
const ll MOD1 = 1000000007;
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll SN(char s){return ll(s-'0');}
ll SN(string s){return stoll(s);}
int alpN(char s){return int(s-'a');}
int AlpN(char s){return int(s-'a');}
using Graph = vector<vector<ll>>;
using mint1 = modint1000000007;
using mint2 = modint998244353;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){for(int i=0;i<(int)v.size();i++)o<<(i>0?" ":"")<<v[i];return o;}//vector空白区切り出力
ostream& operator<<(ostream& os, const mint1& N) {return os << N.val();}//mint出力。デフォはmint1
ostream& operator<<(ostream& os, const mint2& N) {return os << N.val();}
template<class T> bool contain(const std::string& s, const T& v) {
    return s.find(v) != std::string::npos;
}

#endif
0