結果

問題 No.2576 LCM Pattern
ユーザー maeshunmaeshun
提出日時 2023-12-13 16:39:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,273 bytes
コンパイル時間 4,751 ms
コンパイル使用メモリ 268,956 KB
実行使用メモリ 814,176 KB
最終ジャッジ日時 2023-12-13 16:39:29
合計ジャッジ時間 9,560 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 11 ms
7,968 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 TLE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
//long longだとおそい
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

int main()
{
    int n, m;
    cin >> n >> m;
    Sieve s(m);
    auto ps = s.factor(m);
    dbg(ps);
    int sum = 0;
    mint val = 1;
    for(auto [p, cnt] : ps){
        val *= cnt+1;
        sum += cnt;
    }
    // mint ans = val.pow(n);
    // dbg(ans.val());
    mint ans = 0;
    int N = ps.size();
    rep(i,1<<N){
        mint now = 1;
        rep(j,N) {
            if(i>>j&1) {
                now *= ps[j].second;
            }
            else{
                now *= ps[j].second+1;
            }
        }
        if(__builtin_popcount(i)%2==0) ans += now.pow(n);
        else ans -= now.pow(n);
    }
    cout << ans.val() << endl;
    return 0;
}
0