結果

問題 No.2896 Monotonic Prime Factors
ユーザー umimel
提出日時 2024-09-20 22:10:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 4,211 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 175,108 KB
実行使用メモリ 46,972 KB
最終ジャッジ日時 2024-09-20 22:11:25
合計ジャッジ時間 3,759 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 2;
template<long long mod>
class modint{
long long x;
public:
modint(long long x=0) : x((x%mod+mod)%mod) {}
modint operator-() const {
return modint(-x);
}
bool operator==(const modint& a){
if(x == a) return true;
else return false;
}
bool operator==(long long a){
if(x == a) return true;
else return false;
}
bool operator!=(const modint& a){
if(x != a) return true;
else return false;
}
bool operator!=(long long a){
if(x != a) return true;
else return false;
}
modint& operator+=(const modint& a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
modint& operator-=(const modint& a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
modint& operator*=(const modint& a) {
(x *= a.x) %= mod;
return *this;
}
modint operator+(const modint& a) const {
modint res(*this);
return res+=a;
}
modint operator-(const modint& a) const {
modint res(*this);
return res-=a;
}
modint operator*(const modint& a) const {
modint res(*this);
return res*=a;
}
modint pow(long long t) const {
if (!t) return 1;
modint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
modint inv() const {
return pow(mod-2);
}
modint& operator/=(const modint& a) {
return (*this) *= a.inv();
}
modint operator/(const modint& a) const {
modint res(*this);
return res/=a;
}
friend std::istream& operator>>(std::istream& is, modint& m) noexcept {
is >> m.x;
m.x %= mod;
if (m.x < 0) m.x += mod;
return is;
}
friend ostream& operator<<(ostream& os, const modint& m){
os << m.x;
return os;
}
};
using mint = modint<MOD998244353>;
template<typename T>
struct combination{
vector<T> fac, ifac;
combination(size_t n=0) : fac(1, 1), ifac(1, 1){
make_table(n);
}
void make_table(size_t n){
if(fac.size()>n) return;
size_t now = fac.size();
n = max(n, now*2);
fac.resize(n+1);
ifac.resize(n+1);
for(size_t i=now; i<=n; i++) fac[i] = fac[i-1]*i;
ifac[n]=T(1)/fac[n];
for(size_t i=n; i-->now; ) ifac[i] = ifac[i+1]*(i+1);
}
T factorial(size_t n){
make_table(n);
return fac[n];
}
T invfac(size_t n){
make_table(n);
return ifac[n];
}
T P(size_t n, size_t k){
if(n < k) return 0;
make_table(n);
return fac[n]*ifac[n-k];
}
T C(size_t n, size_t k){
if(n < k) return 0;
make_table(n);
return fac[n]*ifac[n-k]*ifac[k];
}
T H(size_t n, size_t k){
if(n==0) return k==0?1:0;
return C(n-1+k, k);
}
};
combination<mint> comb;
void solve(){
int MAX = 1e5;
vector<bool> is_prime(MAX+1, true);
is_prime[0] = is_prime[1] = false;
for(int i=2; i<=MAX; i++){
if(!is_prime[i]) continue;
for(int j=2*i; j<=MAX; j+=i){
is_prime[j] = false;
}
}
vector<int> prime;
for(int i=0; i<=400; i++) if(is_prime[i]) prime.pb(i);
int q; cin >> q;
int cnt = 0;
while(q--){
int a, b; cin >> a >> b;
for(int p : prime){
while(a%p==0){
cnt++;
a/=p;
}
}
if(a != 1) cnt++;
mint ans = 0;
if(cnt>=b) ans = comb.C(cnt-1, b-1);
cout << ans << '\n';
}
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int T=1;
//cin >> T;
while(T--) solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0