记录编号 305747 评测结果 AAAAAAAAAA
题目名称 [NOIP 2014]解方程 最终得分 100
用户昵称 GravatarKZNS 是否通过 通过
代码语言 C++ 运行时间 0.778 s
提交时间 2016-09-11 09:50:55 内存使用 7.13 MiB
显示代码纯文本
//KZNS
//Best Wil
#include <cstdio>
#include <algorithm>
using namespace std;
int p[5] = {11261, 19997, 22877, 21893, 14843};
int a[105][5] = {0};
int ls[1000003] = {0};
int N, M;
void rin() {
	scanf("%d %d", &N, &M);
	char c;
	int f;
	for (int i = 0; i <= N; i++) {
		f = 1;
		c = getchar();
		while (!('0' <= c && c <= '9')) {
			if (c == '-')
				f = -1;
			c = getchar();
		}
		while ('0' <= c && c <= '9') {
			for (int k = 0; k < 5; k++)
				a[i][k] = (a[i][k]*10+c-'0')%p[k];
			c = getchar();
		}
		for (int k = 0; k < 5; k++)
			a[i][k] *= f;
	}
}
bool ck(int t, int k) {
	int u = 1;
	int ans = 0;
	for (int i = 0; i <= N; i++) {
		ans = (ans + a[i][k]*u)%p[k];
		u = u*t%p[k];
	}
	if (ans)
		return false;
	else
		return true;
}
int anls[1000003] = {0};
int anu = 0;
void work() {
	int mn;
	int u;
	for (int k = 0; k < 5; k++) {
		mn = min(M, p[k]);
		for (int i = 1; i <= mn; i++) {
			if (ck(i, k)) {
				ls[i]++;
				u = i;
				while (u + p[k] <= M) {
					u += p[k];
					ls[u]++;
				}
			}
		}
	}
	for (int i = 1; i <= M; i++) {
		if (ls[i] == 5)
			anls[anu++] = i;
	}
	printf("%d\n", anu);
	for (int i = 0; i < anu; i++)
		printf("%d\n", anls[i]);
}
int main() {
	freopen("equationa.in", "r", stdin);
	freopen("equationa.out", "w", stdout);
	rin();
	work();
	return 0;
}
//All Illu
//UBWH