$Noip2014/Luogu2312$ 解方程

$Luogu$

 

$Sol$

枚举解+秦九韶公式计算+取模.

 

$Code$

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define il inline
#define Rg register
#define go(i,a,b) for(Rg int i=a;i<=b;++i)
#define yes(i,a,b) for(Rg int i=a;i>=b;--i)
#define e(i,u) for(Rg int i=b[u];i;i=a[i].nt)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define db double
#define inf 2147483647
using namespace std;
const int N=1000010,mod=1000000007;
il int read()
{
    ll x=0;int y=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=((x<<1)%mod+(x<<3)%mod+c-'0')%mod;c=getchar();}
    return x*y;
}
int n,m,ct,as[N],a[N];
il bool ck(int x)
{
    ll ret=0;
    yes(i,n,0)ret=(ret*x%mod+a[i])%mod;
    if(ret==0)return 1;return 0;
}
int main()
{
    n=read(),m=read();
    go(i,0,n)a[i]=read();
    go(i,1,m)if(ck(i))as[++ct]=i;
    printf("%d\n",ct);
    go(i,1,ct)printf("%d\n",as[i]);
    return 0;
}
View Code

 

 

 

posted @ 2019-10-03 14:49  DTTTTTTT  阅读(87)  评论(0编辑  收藏  举报