题解:UVA1635 无关的元素 Irrelevant Elements
UVa1635
Solution
相邻两个求和,最终结果明显是
接下来就找这些
首先会想到用乘法逆元求组合数,但是会发现根本不能取模,也没有保证
我们先把
要判断是否被
我们知道组合数是一堆阶乘的乘除,所以预处理
最后就来比较每个质因数的幂大小,由组合数公式可得:
如果对于
Code
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL n,m;
vector<pair<LL,LL> > g;
vector<LL> ans;
LL v[1005][100005];
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>m;
LL x=m;
for(int p=2; (LL)p*p<=x; p++){
if(x%p==0){
int e=0;
while(x%p==0){ x/=p; e++; }
g.push_back({p,e});
}
}
if(x>1) g.push_back({x,1});
LL len=g.size();
for(int t=0; t<len; t++){
LL p=g[t].first;
v[t][0]=0;
for(int i=1; i<n; i++){
LL c=0, x=i;
while(x%p==0){ x/=p; c++; }
v[t][i]=v[t][i-1]+c;
}
}
for(int j=0; j<n; j++){
bool flag=true;
for(int t=0; t<len; t++){
LL tot = v[t][n-1] - v[t][j] - v[t][n-1-j];
if(tot<g[t].second){ flag=0; break; }
}
if(flag) ans.push_back(j+1);
}
cout<<ans.size()<<endl;
for(LL i:ans) cout<<i<<" ";
return 0;
}