P2312 解方程
题目描述
已知多项式方程:
a0+a1x+a2x^2+..+anx^n=0
求这个方程在[1, m ] 内的整数解(n 和m 均为正整数)
输入输出格式
输入格式:
输入文件名为equation .in。
输入共n + 2 行。
第一行包含2 个整数n 、m ,每两个整数之间用一个空格隔开。
接下来的n+1 行每行包含一个整数,依次为a0,a1,a2..an
输出格式:
输出文件名为equation .out 。
第一行输出方程在[1, m ] 内的整数解的个数。
接下来每行一个整数,按照从小到大的顺序依次输出方程在[1, m ] 内的一个整数解。
输入输出样例
2 10
1
-2
1
1
1
2 10
2
-3
1
2
1
2
2 10
1
3
2
0
说明
30%:0<n<=2,|ai|<=100,an!=0,m<100
50%:0<n<=100,|ai|<=10^100,an!=0,m<100
70%:0<n<=100,|ai|<=10^10000,an!=0,m<10000
100%:0<n<=100,|ai|<=10^10000,an!=0,m<1000000
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int mod[]={,,,,};
int n,m;
int ans[];
int a[][],pre[][],res[][];
char ch[];
inline int cal(int t,int x)
{
int sum=;
for(int i=;i<=n;i++)
sum=(sum+a[t][i]*pre[t][i])%mod[t];
if(sum<)sum+=mod[t];
return sum;
}
inline bool jud(int x)
{
for(int t=;t<;t++)
if(res[t][x%mod[t]]!=)return ;
return ;
}
int main()
{
n=read();m=read();
for(int i=;i<=n;i++)
{
scanf("%s",ch+);
int l=strlen(ch+);
bool flag=;
for(int t=;t<;t++)
if(ch[]!='-')a[t][i]=ch[]-'';
else a[t][i]=,flag=;
for(int t=;t<;t++)
{
for(int k=;k<=l;k++)
a[t][i]=(a[t][i]*+ch[k]-'')%mod[t];
if(flag)a[t][i]=-a[t][i];
}
}
for(int t=;t<;t++)
for(int x=;x<mod[t];x++)
{
pre[t][]=;
for(int i=;i<=n;i++)pre[t][i]=(pre[t][i-]*x)%mod[t];
res[t][x]=cal(t,x);
}
for(int i=;i<=m;i++)
if(jud(i))ans[++ans[]]=i;
printf("%d\n",ans[]);
for(int i=;i<=ans[];i++)
printf("%d\n",ans[i]);
return ;
}
P2312 解方程的更多相关文章
- codevs3732==洛谷 解方程P2312 解方程
P2312 解方程 195通过 1.6K提交 题目提供者该用户不存在 标签数论(数学相关)高精2014NOIp提高组 难度提高+/省选- 提交该题 讨论 题解 记录 题目描述 已知多项式方程: a ...
- bzoj3751 / P2312 解方程
P2312 解方程 bzoj3751(数据加强) 暴力的一题 数据范围:$\left | a_{i} \right |<=10^{10000}$.连高精都无法解决. 然鹅面对这种题,有一种常规套 ...
- 洛谷 P2312 解方程 解题报告
P2312 解方程 题目描述 已知多项式方程: \(a_0+a_1x+a_2x^2+\cdots+a_nx^n=0\)求这个方程在 \([1,m]\) 内的整数解(\(n\) 和 \(m\) 均为正整 ...
- 洛谷P2312 解方程题解
洛谷P2312 解方程题解 题目描述 已知多项式方程: \[a_0+a_1x+a_2x^2+\cdots+a_nx^n=0\] 求这个方程在 \([1,m]\) 内的整数解(\(n\) 和 \(m\) ...
- 洛谷 P2312 解方程 题解
P2312 解方程 题目描述 已知多项式方程: \[a_0+a_1x+a_2x^2+\cdots+a_nx^n=0\] 求这个方程在 [1,m][1,m] 内的整数解(\(n\) 和 \(m\) 均为 ...
- [noip2014]P2312 解方程
P2312 解方程 其实这道题就是求一个1元n次方程在区间[1, m]上的整数解. 我们枚举[1, m]上的所有整数,带进多项式中看看结果是不是0即可. 这里有一个技巧就是秦九韶算法,请读者自行查看学 ...
- P2312 解方程(随机化)
P2312 解方程 随机化的通俗解释:当无法得出100%正确的答案时,考虑随机化一波,于是这份代码很大可能会对(几乎不可能出错). 比如这题:把系数都模一个大质数(也可以随机一个质数),然后O(m)跑 ...
- [NOIP2014] 提高组 洛谷P2312 解方程
题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .i ...
- 洛谷 P2312 解方程
题目 首先,可以确定的是这题的做法就是暴力枚举x,然后去计算方程左边与右边是否相等. 但是noip的D2T3怎么会真的这么简单呢?卡常卡的真是熟练 你需要一些优化方法. 首先可以用秦九韶公式优化一下方 ...
- 【数论】[涨姿势:同余]P2312解方程
题目描述 已知多项式方程:\(a_0 + a_1x + a_2x^2+...+a_nx^n = 0\) 求这个方程在[1,m]内的整数解 \(1\leq n\leq100,|a_i|\leq 10^{ ...
随机推荐
- Android 测试Service的生命周期
package com.example.myapp4; import android.support.v7.app.ActionBarActivity; import android.content. ...
- angular form 验证 ngMessage
<!DOCTYPE HTML> <html ng-app="deliciousApp"> <head> <meta charset=&qu ...
- mongodb版本管理
使用gradle. 查找最新版本http://mvnrepository.org/ compile "org.mongeez:mongeez:0.9.6" 配置spring < ...
- ORACLE 默认密码确认
select USER_NAME USER_WITH_DEFAULT_PASSWORD from ( select fnd_web_sec.validate_login('AME_INVALID_AP ...
- full_case & parallel_case
case中的full_case与parallel_case讨论: 1)术语介绍: 整个case模块叫做:case_statement,注释部分叫做case_statement_header case ...
- z/os上的tar和gzip
在*nix平台上玩过的人都知道,tar和gzip基本上是每天都要使用的,而且非常之好用.而Mainframer则比较痛苦,没有这么好用的东西,尤其是当需要通过网络传大批量的文件的时候很不方便. 不过总 ...
- js 点击按钮显示下拉菜单
<li> <a id = "rank" onclick="showGroup()"></a></li><l ...
- CSS中的各个选择节点,都有样式最后一个无样式的快捷解决方法
2.1.3 多标签 多标签选择器一般和html上下文有关,它有以下集中分类 选择一个祖先的所有子孙节点,例如 div p{…} 选择一个父元素的所有直属节点,例如 div > p{…} 选择某一 ...
- 电脑远程工具:mstsc
外网远程控制:电脑远程连接在开始程序中搜:mstsc 然后直接敲IP地址 工具:dell sonicwall netextender.exe mstsc.exe 内网远程控制:使用TeamVi ...
- linux驱动的入口函数module_init的加载和释放【转】
本文转载自:http://blog.csdn.net/zhandoushi1982/article/details/4927579 就像你写C程序需要包含C库的头文件那样,Linux内核编程也需要包含 ...