标签:解方程 www false for 通过 getchar int cal char
怎么求解呢?
其实我们可以把左边的式子当成一个算式来计算,从1到m枚举,只要结果是0,那么当前枚举到的值就是这个等式的解了。可以通过编写一个bool函数来判断算式的值是不是0~
至于如何计算这个看起来又臭又长(雾)的多项式,用秦九韶算法就可以解决啦~
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int p=1000000007;
bool t=true;
int n,m,ans,cnt,sum=0;
int A[103],key[1000003];
ll read()
{
ll sum=0,fg=1;
char c=getchar();
while(c < ‘0‘ || c > ‘9‘)
{
if(c==‘-‘) fg=-1;
c=getchar();
}
while(c >=‘0‘ && c <=‘9‘)
{
sum=((sum*10)+c-‘0‘)%p;
c=getchar();
}
return sum*fg;
}
void print(int x)
{
if(x<0)
{
putchar(‘-‘);
x=-x;
}
if(x>9)
{
print(x/10);
}
putchar(x%10+‘0‘);
}
bool calc(ll x)
{
sum=0;
for(ll i=n;i>=1;i--)
{
sum=((A[i]+sum)*x)%p;
}
sum=(sum+A[0])%p;
return !sum;
}
int main()
{
n=read();
m=read();
for(ll i=0;i<=n;i++)
{
A[i]=read();
}
for(ll i=1;i<=m;i++)
{
if(calc(i))
{
t=false;
ans++;
key[++cnt]=i;
}
}
if(t)
{
cout<<ans<<endl;
return 0;
}
print(ans);
printf("\n");
for(ll i=1;i<=cnt;i++)
{
print(key[i]);
printf("\n");
}
return 0;
}
标签:解方程 www false for 通过 getchar int cal char
原文地址:https://www.cnblogs.com/ainiyuling/p/11485601.html