すきだよ

导航

codeforces 1750_D

https://codeforces.com/contest/1750/problem/D

#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<string>
#include<stack>
#include<algorithm>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cstring>
#include <numeric>
using namespace std;
const int mod=998244353;
typedef long long ll;
vector<int> sp(ll n){
    vector<int>res;
    if(n%2==0) res.push_back(2);
    while(n%2==0) n=n/2;
    for(int i=3;i*i<=n;i+=2){
        if(n%i==0) res.push_back(i);
        while(n%i==0) n=n/i;
    }
    if(n!=1) res.push_back(n);
    return res;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,m,pd=0;
        cin>>n>>m;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin>>v[i];
        for(int i=0;i<n-1;i++){
            if(v[i]%v[i+1]!=0) pd=1;
        }
        if(pd) cout<<0<<endl;
        else{
            ll ans=1;
            for(int i=0;i<v.size()-1;i++){
                if(v[i]==v[i+1]) {
                    ans=(ans*(m/v[i]))%mod;
                    continue;
                }
                ll x=v[i]/v[i+1];
                ll base=m/v[i+1];
                vector<int>fc=sp(x);
                int n=fc.size();
                for(int j=1;j<(1<<n);j++){
                    ll sign=1,a=j,b=1;
                    for(int k=0;k<n;k++){
                        if(a&1) {
                            sign*=-1;
                            b=(b*fc[k]);
                        }
                        a=a>>1;
                    }
                    base+=sign*(m/(b*v[i+1]));
                }
                ans=(ans*base)%mod;
            }
            cout<<ans<<endl;
        }
    }
    system("pause");
}

posted on 2022-11-08 17:34  すきだよ  阅读(18)  评论(0编辑  收藏  举报