NOIP2014 解方程

解方程

这道题用秦九韶算法就可以把原本 n 2 n^2 n2的算法优化到 n n n次乘法与 n n n次加法了(直接推的话只要有点文化课数学基础也是很好推的)
这道题卡点并不在时间复杂度与算法,而是为了避免高精度要 % \% %一个大质数比如 1 e 9 + 7 1e9+7 1e9+7之类的。这题写成这样我们仍然只能获得 30 p t s 30pts 30pts的好成绩 最丧心病狂的是这题在读入优化的时候也要记得取模!!!出题人你没有心
记得取模就过了

#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int Mod=1e9+7;
const int N=150;
const int M=1e6+50;
int n,m,v[N],ans,cnt,b[M];
inline int read(){
	int cnt=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-f;c=getchar();}
	while(isdigit(c)){cnt=(cnt<<1)+(cnt<<3)+(c^48);cnt=cnt%Mod;c=getchar();}
	return cnt*f;
}
signed main(){
	n=read(),m=read();
	for(int i=0;i<=n;++i) v[i]=read()%Mod;
	ans=v[n]%Mod;
	for(int i=1;i<=m;++i){
		ans=v[n];
		for(int j=n-1;j>=0;--j){
			ans=(ans*i%Mod+v[j])%Mod;
		}
		if(ans==0) b[++cnt]=i;
//		cerr<<i<<' '<<ans<<endl;
	}
	printf("%lld\n",cnt);
	for(int i=1;i<=cnt;++i){
		printf("%lld\n",b[i]%Mod);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值