题目描述

已知多项式方程:\(a_0 + a_1x + a_2x^2+...+a_nx^n = 0\)

求这个方程在[1,m]内的整数解

\(1\leq n\leq100,|a_i|\leq 10^{10000},a_n≠0,m\leq 10^6\)

Solution

首先由于数据过大,只能字符串读入了hhh。然后:对于每个x,算出f(x)%pi,如果f(x)=0则f(x)%pi必然=0,多选几个素数,就可以在一定范围大小内判断成功。好像不够快?

\(f(x+p)≡f(x)(mod p)\)

对于一个x,\(f(x)≠0(mod p)\),则x+p,x+2p……均不为方程的解

有了这个性质就可以瞎搞了。取几个较大的质数搞一搞……

Code

#include <iostream>
#include <cstdio>
using namespace std;
inline long long read() {
long long x = 0; int f = 0; char c = getchar();
while (c < '0' || c > '9') f |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f? -x:x;
} long long a[110][4], mod[4] = {10007, 11003, 12007, 13001};
int b[1000010], n, m;
string qwq;
bool check(long long x) {
for (int k = 0; k < 4; k++) {
long long tmp = a[n][k];
for (int i = n - 1; i >= 0; i--)
tmp = (tmp * x + a[i][k]) % mod[k];
if (tmp) {
for (int i = x; i <= m; i += mod[k]) b[i] = 1;
return 0;
}
}
return 1;
}
int main() {
n = read(); m = read();
for (int i = 0; i <= n; ++i) {
cin >> qwq;
for (int k = 0; k < 4; ++k) {
long long flg = 1, tmp = 0;
for (int j = 0; j < qwq.length(); ++j)
if (qwq[j] == '-') flg = -1;
else tmp = ((tmp << 1) + (tmp << 3) + (qwq[j] ^ 48)) % mod[k];
a[i][k] = tmp * flg;
}
}
int ans = 0;
for (int x = 1; x <= m; x++)
if (!b[x] && check(x)) ans++;
printf("%d\n", ans);
for (int i = 1; i <= m; i++)
if (!b[i]) printf("%d\n", i);
return 0;
}

最新文章

  1. noip2016十连测round2
  2. cocos2d-x 之 内存管理(5)
  3. AspNet MVC 缓存
  4. quick-cocos2d-x学习笔记—定时器
  5. PHP安全函数phpinfo()
  6. 解决方法:loadrunner 场景下执行webservice脚本是---报错10492 Error: Exception was raised when calling per-process-init function in extens
  7. DataGridView控件判断滚动条是否滚动到当前已加载的数据行底部
  8. jQuery之防止冒泡事件
  9. 无向图求割点 UVA 315 Network
  10. Aone新拉分支
  11. 关于PHPAPI ZEND_API TSRM_API宏的定义
  12. JAVA设计模式初探之适配器模式
  13. 51nod1222 最小公倍数计数
  14. XML与HTML区别
  15. MFC中调用web api
  16. 【奇奇怪怪的bug系列】微信小程序
  17. mysql 远程访问不行解决方法 Host is not allowed to connect to this MySQL server
  18. 金融应用,计算将来的学费 Exercise05_07
  19. Problem R: 求斐波那契数列的前n项值
  20. python-class(5)

热门文章

  1. gitblit搭建
  2. 错误排查:Cloudera Manager Agent 的 Parcel 目录位于可用空间小于 10.0 吉字节 的文件系统上。 /opt/cloudera/parcels
  3. BUAA-OO-2019 第一单元总结
  4. 汽车行业如何个性化定制转型?看APS系统在这家企业的运用
  5. django memcached/redis缓存 =====缓存session
  6. phpstorm goland webstorm jetbrain
  7. CentOS6.7安装部署之Tomcat多实例
  8. scratch2.0的教材视频,王木头系列
  9. 基于SCRUM方法实践的西油计科党建设计与实现
  10. k8s Storage Classes