3751: [NOIP2014]解方程

题目连接:

http://www.lydsy.com/JudgeOnline/problem.php?id=3751

Description

已知多项式方程:

a0+a1*x+a2*x^2+...+an*x^n=0

求这个方程在[1,m]内的整数解(n和m均为正整数)。

Input

第一行包含2个整数n、m,每两个整数之间用一个空格隔开。

接下来的n+1行每行包含一个整数,依次为a0,a1,a2,...,an。

Output

第一行输出方程在[1,m]内的整数解的个数。

接下来每行一个整数,按照从小到大的顺序依次输出方程在[1,m]内的一个整数解。

Sample Input

2 10

2

-3

1

Sample Output

2

1

2

Hint

对于100%的数据,0<n≤100,|ai|≤1010000,an≠0,m≤1000000。

题意

题解:

找6个10000左右的素数,然后把这个素数范围内的数拿去测试就好了

因为 (a % p) = (a+p % p),所以a不合适,那么a+p肯定也是不合适的。

于是用这个方法去xjb筛一波就好了。

代码

#include<bits/stdc++.h>
using namespace std; const int maxn = 105;
const int N = 1e6+6;
int p[10]={19997,22877,14843,10007,11261,21893};
char s[105][10005];
int flag[N];
int a[maxn],n,m,len[maxn];
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<=n;i++)
scanf("%s",s[i]);
for(int i=0;i<=n;i++)
len[i]=strlen(s[i]);
for(int o=0;o<6;o++){
for(int i=0;i<=n;i++){
int flag = (s[i][0]=='-')?1:0;
a[i]=0;
for(int j=flag;j<len[i];j++){
a[i]=(a[i]*10+(s[i][j]-'0'))%p[o];
}
if(flag)a[i]=-a[i];
}
for(int i=1;i<=p[o];i++){
int tmp=0;
for(int j=n;j>=0;j--)
tmp=(tmp*i+a[j])%p[o];
if(tmp)for(int j=0;i+j*p[o]<=m;j++)
flag[i+j*p[o]]=1;
}
}
int ans = 0;
for(int i=1;i<=m;i++)if(!flag[i])ans++;
cout<<ans<<endl;
for(int i=1;i<=m;i++)
if(!flag[i])
cout<<i<<endl;
}

BZOJ 3751: [NOIP2014]解方程 数学的更多相关文章

  1. bzoj 3751: [NOIP2014]解方程 同余系枚举

    3.解方程(equation.cpp/c/pas)[问题描述]已知多项式方程:a ! + a ! x + a ! x ! + ⋯ + a ! x ! = 0求这个方程在[1, m]内的整数解(n 和 ...

  2. bzoj 3751: [NOIP2014]解方程【数学】

    --我真是太非了,自己搞了7个质数都WA,从别人那粘5个质数就A了-- 就是直接枚举解,用裴蜀定理计算是否符合要求,因为这里显然结果很大,所以我们对多个质数取模看最后是不是都为0 #include&l ...

  3. bzoj 3751: [NOIP2014]解方程

    Description 已知多项式方程: a0+a1x+a2x^2+...+an*x^n=0 求这个方程在[1,m]内的整数解(n和m均为正整数). 解题报告: 这题比较诡,看到高精度做不了,就要想到 ...

  4. 【BZOJ】3751: [NOIP2014]解方程【秦九韶公式】【大整数取模技巧】

    3751: [NOIP2014]解方程 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 4856  Solved: 983[Submit][Status ...

  5. 【BZOJ】3751: [NOIP2014]解方程

    题意 求\(\sum_{i=0}^{n} a_i x^i = 0\)在\([1, m]\)内的整数解.(\(0 < n \le 100, |a_i| \le 10^{10000}, a_n \n ...

  6. [BZOJ3751] [NOIP2014] 解方程 (数学)

    Description 已知多项式方程:$a_0+a_1*x+a_2*x^2+...+a_n*x^n=0$ 求这个方程在[1,m]内的整数解(n和m均为正整数). Input 第一行包含2个整数n.m ...

  7. [BZOJ3751][NOIP2014]解方程(数学相关+乱搞)

    题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .i ...

  8. LOJ2503 NOIP2014 解方程 【HASH】

    LOJ2503 NOIP2014 解方程 LINK 题目大意就是给你一个方程,让你求[1,m]中的解,其中系数非常大 看到是提高T3还是解方程就以为是神仙数学题 后来研究了一下高精之类的算法发现过不了 ...

  9. [NOIP2014]解方程

    3732 解方程  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 输入描述 Input Descrip ...

随机推荐

  1. Linux查看用户密码修改时间

    在/etc/shadow文件里面,第三个字段标识表示密码修改日期:这个是表明上一次修改密码的日期与1970-1-1相距的天数.如果账户自创建后,没有修改过密码,就可以使用这个字段来查找账号创建日期. ...

  2. 【LinuxC】GCC编译C程序,关闭随机基址

    1.编译.链接和运行程序 C代码示例: #include <stdio.h> #include <stdlib.h> int main() { printf("hel ...

  3. python目前安装的包备份

    Package Version ------------------------------- ------------------ alembic altgraph 0.14 apistar app ...

  4. Focal Loss笔记

    论文:<Focal Loss for Dense Object Detection> Focal Loss 是何恺明设计的为了解决one-stage目标检测在训练阶段前景类和背景类极度不均 ...

  5. 移动端Touch事件

    案例1: <!doctype html> <html lang="en"> <head> <meta charset="UTF- ...

  6. node项目中用到的一些模块

    1.http模块,用来搭建服务器 代码,简单服务器实现 var http = require('http'); http.createServer(function (request, respons ...

  7. Codeforces 734C Anton and Making Potions(枚举+二分)

    题目链接:http://codeforces.com/problemset/problem/734/C 题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,第一类周瑜有m种,每种 ...

  8. Fix Valgrind's must-be-redirected error in Gentoo

    Last week, I tried to use Valgrind to identify potential memory related bugs, since segmentation fau ...

  9. wordpress 常用函数-wpdb类

    与数据库建立接口 WordPress为用户提供了一系列用于数据库操作的函数类——wpdb.Wpdb类建立在Justin Vincent编写并维护的ezSQL类的基础上. 使用须知 不可直接调用wpdb ...

  10. appium----新版appium 1.11.1 支持ByName定位

    org.openqa.selenium.InvalidSelectorException: Locator Strategy 'name' is not supported for this sess ...