結果
| 問題 |
No.2896 Monotonic Prime Factors
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-28 10:49:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 581 ms / 2,000 ms |
| コード長 | 3,034 bytes |
| コンパイル時間 | 1,235 ms |
| コンパイル使用メモリ | 123,512 KB |
| 最終ジャッジ日時 | 2025-02-24 13:52:35 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
using ll = long long;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const int dy[]={0,1,0,-1};
const int dx[]={1,0,-1,0};
const int mod = 998244353;
struct mint {
long long x; // typedef long long long long;
mint(long long x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}//後ろのconstはメンバxを変更しないことを示す
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
bool operator==(const mint a) const {return a.x==x;}
mint pow(unsigned long long int t) const {
assert(t>=0);
if (!t) return 1;
//aがtで割り切れない場合には t%=(mod-1)をして良い
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;}
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;}
struct combination {
std::vector<mint> fact, ifact;
combination(int n):fact(n+1),ifact(n+1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
};
combination comb(45*100000);
int main(){
int Q;
cin>>Q;
vector<ll> A(Q),B(Q);
for(int q=0;q<Q;q++){
cin>>A[q]>>B[q];
}
auto add=[&](ll v){
map<ll,ll> mp;
for(ll d=2;d*d<=v;d++){
if(v%d==0){
while(v%d==0){
mp[d]++;
v/=d;
}
}
}
if(v!=1) mp[v]++;
return mp;
};
ll cnt=0;
vector<mint> ans(Q);
for(int q=0;q<Q;q++){
ll a=A[q],b=B[q];
auto mp=add(a);
for(auto p:mp){
cnt+=p.second;
}
ll v=cnt-B[q];
if(v<0){
ans[q]=0;
}else{
//仕切りの数がB[q]-1個
ans[q]=comb(v+B[q]-1,B[q]-1);
}
}
for(int q=0;q<Q;q++){
cout<<ans[q]<<endl;
}
}