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<=sqrt(n);i+=2){
if(n%i==0) res.push_back(i);
while(n%i==0) n=n/i;
}
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);
fc.push_back(x);
int n=fc.size();
for(int j=0;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*b;
}
ans=(ans*base)%mod;
}
cout<<ans<<endl;
}
}
system("pause");
}
标签:int,codeforces,back,ans,include,1750
From: https://www.cnblogs.com/God-Destiny/p/16870546.html