题意:
大概就是输出C(n,k)不能整除 m
看来LRJ 的解析,开始不知道输出方式0.0
一直WA ,还以为哪里爆了int,结果.............
可以优化0.0
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
typedef unsigned long long ULL;
ULL Primes[5000];
ULL Pos[5000];
int Num[100031];
int Count;
ULL N,M;
int GetPos(int k,int P) {
int ans = 0;
if(k == 0) return ans;
else {
ULL temp = P;
while(k / temp) {
ans += k / temp;
temp *= P;
}
return ans;
}
}
void GetPrimes(int m) {
Count = 0;
memset(Primes,0,sizeof(Primes));
memset(Pos,0,sizeof(Pos));
int T = int(sqrt(m+0.5) + 1);
for(int i = 2; i <= T; ++i) {
if(m % i == 0) Primes[Count] = i;
while(m % i == 0) {
m /= i;
Pos[Count] ++;
}
if(Pos[Count]) Count++;
}
if(m >= 2) Primes[Count] = m, Pos[Count++] = 1;
//for(int i = 0; i < Count; ++i) cout << Primes[i] << " " << Pos[i] << endl;
}
int main() {
while(cin >> N >> M) {
GetPrimes(M);
int pos = 0;
for(int i = 1; i <= N; ++i) {
bool jug = true;
for(int j = 0; j < Count; ++j){
int k = GetPos(N-1,Primes[j]) - GetPos(i-1,Primes[j]) - GetPos(N-i,Primes[j]);
if(k < Pos[j]) {
jug = false;
break;
}
}
if(jug) Num[pos++] = i;
}
cout << pos << endl;
for(int i = 0; i < pos; ++i) if(i) cout <<" " << Num[i]; else cout << Num[i];
cout << endl;
}
return 0;
}