比赛 欢乐五一练练练 评测结果 AAAAAAAAAA
题目名称 解方程 最终得分 100
用户昵称 sxysxy 运行时间 0.770 s
代码语言 C++ 内存使用 2.25 MiB
提交时间 2017-04-26 19:18:43
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstdarg>
#include <queue>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
int rapiz[] = {9967, 9903, 9973, 10007, 10037, 10103};
int sz = sizeof(rapiz)/sizeof(int);
int lens[102];
char exps[102][10003];
int n, m;
void read_data()
{
    scanf("%d %d", &n, &m);
    for(int i = 0; i <= n; i++)
    {
        scanf("%s", exps[i]);
        lens[i] = strlen(exps[i]);
    }
}
int modp(char *s, int l, int mod)
{
    int r = 0;
    int sig = s[0] == '-';
    for(int i = sig; i < l; i++)
        r = ((r<<3)+(r<<1)+(s[i]^0x30))%mod;
    if(sig)r = (mod-r)%mod;
    return r;
}
int t[10003];
bool cannot[1000003];
void check(int Rapiz)
{
    for(int i = 0; i <= n; i++)
        t[i] = modp(exps[i], lens[i], Rapiz);
    for(int x = 1; x <= m && x <= Rapiz; x++) //test x
    {
        int r = 0;
        for(int j = n; j >= 0; j--)
            r = (r * (x%Rapiz)%Rapiz + t[j])%Rapiz;
        if(r)
            for(int j = x; j <= m; j += Rapiz)
                cannot[j] = true;
    }
}
void solve()
{
    for(int i = 0; i < sz; i++)
        check(rapiz[i]);
    int nots = 0;
    for(int i = 1; i <= m; i++)nots += cannot[i];
    int ans = m-nots;
    printf("%d\n", ans);
    for(int i = 1; i <= m; i++)if(!cannot[i])
                                printf("%d\n", i);
}
int main()
{
    freopen("equationa.in", "r", stdin);
    freopen("equationa.out", "w", stdout);
    read_data();
    solve();
    return 0;
}