比赛 20160316 评测结果 AAAAAAAAAA
题目名称 无关的数 最终得分 100
用户昵称 Fmuckss 运行时间 0.155 s
代码语言 C++ 内存使用 0.32 MiB
提交时间 2016-03-16 22:40:12
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long LL;
LL n, m;
LL gcd(LL a, LL b) {
	return b == 0 ?  a : gcd(b, a%b);
} 
vector<LL> sol;
LL up, down;
void handle1(LL x) {
	LL tmp = gcd(x, m); 
	while(tmp != 1 && x != 1) {//tmp == 1 意味着两个数没有最大公约数 
		up *= tmp;
		x /= tmp;
		tmp = gcd(x, m);
	}
}
void handle2(LL x) {
	LL tmp = gcd(x, m);
	while(tmp != 1 && x != 1) {
		down *= tmp;
		x /= tmp;
		tmp = gcd(x, m);
	}
}
int main() {
	freopen("irre.in", "r", stdin);
	freopen("irre.out", "w", stdout); 
	scanf("%lld %lld", &n, &m);//要求第n行的数,其实是求c(n-1, i)  
	//即对于n的第2~n/2位处理,如9,2=> c(8,1) 9,3=>c(8,2) 
	up = 1; down = 1;
	LL tmp;
	for(LL i = 2; i < n; i++) {//从第2到第n-1 n,i c(n-1, i-1)
		handle1(n-i+1);
		handle2(i-1);
//		printf("%d %d %d\n",i , up, down);
		tmp = gcd(up, down);
		while(tmp != 1 && up != 1 && down != 1) {
			up /= tmp;
			down /= tmp;
			tmp = gcd(up, down);
		} 
		if(gcd(up, m) == m) {
			sol.push_back(i);
		}
	}
	printf("%d\n",sol.size());
	for(LL i = 0 ; i < sol.size(); i++) {
		printf("%lld ",sol[i]);
	} 
/*	if(n & 1) {
		printf("%d\n",sol.size()*2-1);
		for(LL i = 0; i <= sol.size()-2; i++) {
			printf("%d ", sol[i]);
		}
		printf("%d ",sol[sol.size()-1]);
		for(LL i = sol.size()-2; i >= 0; i--) {
			printf("%d ",n-sol[i]);
		}
	} else {
		printf("%d\n",sol.size()*2);
		for(LL i = 0; i < sol.size(); i++) {
			printf("%d ", sol[i]);
		}
		for(LL i = sol.size()-1; i >= 0; i--) {
			printf("%d ",n-sol[i]);
		}
	}*/ 
	return 0;
}