Let n be a natural number, n ≤ 8. Consider the following equation:
x
n + cn−1x
n−1 + cn−2x
n−2 + . . . + c1x + c0 = 0
where cn−1, cn−2, . . . , c1, c0 are integers and c0 ̸= 0.
It is known that all the n roots of the equation are real numbers. We consider that each root r of
the equation satisfies the condition: −10 ≤ r ≤ 10. Also, there might be roots that appear more than
once.
Find the number of irrational roots of the equation (an irrational root is a root that is an irrational
number).
Input
The input file contains several test cases, each of them as described below.
The first line of the input file contains the value of n. The second line contains the values of cn−1,
cn−2, . . . , c1, c0: each two consecutive values are separated by a single space.
Output
For each test case, print one number — number of irrational roots of the equation.
Sample Input
6
12 -12 -454 -373 3754 1680
Sample Output
2

题意:给你一个首项为1的n阶方程(n<=8),求出方程的无理数的根;

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define CT continue
#define SC scanf
ll _pow(int x,int n)
{ll tmp=1;while(n){if(n&1) tmp*=x;x*=x;n>>=1;}return tmp;
}int n,ans;ll c[14],cc[14];
void solve(int x)
{int h=n;for(int i=h;i>=0;i--) c[i]=cc[i];while(1){ll tmp=0;for(int i=h;i>=0;i--){tmp+=c[i]*_pow(x,i);}if(tmp==0){ans--;if(ans==0) break;h--;for(int i=0;i<=h;i++) c[i]=c[i+1]*(i+1);}else break;}
}int main()
{while(~SC("%d",&n)){for(int i=n-1;i>=0;i--) SC("%lld",&cc[i]);cc[n]=1;ans=n;for(int root=-10;root<=10;root++)solve(root);printf("%d\n",ans);}return 0;
}

  分析:对于一个首项为1的 n阶式子,假设方程有理根是p/q(p,q互素),代入方程后,方程两边同时除以(p/q)^n;同时对两边进行对q的取余可以发现,只能q==1,才能成立。因此说明该方程的有理根只能是

整数,,,然后还要判断一下重根,对于n阶方程,共有n个根,某个根是方程的k阶根如果其让方程的0-k-1导数方程都等于0,,最后无理跟=n-有理根

参考资料:

转载于:https://www.cnblogs.com/smilesundream/p/5806762.html

UVALive 7178 Irrational Roots 多项式的根相关推荐

  1. 2021-03-01 Matlab 多项式的根求解

    Matlab 多项式的根求解 分享一下通过多种不同的方法计算多项式的根. 数值根 使用代换法求根 特定区间内的根 符号根 数值根 roots 函数用于计算系数向量表示的单变量多项式的根. 例如,创建一 ...

  2. matlab根据根求多项式,matlab求解多项式的根

    因此牛顿法也称切线法,是非线性方程求根方法中收敛最快的方 法. 2. matlab 中方程求解的基本命令 roots(p):求多项式方程的根,其中 p 是多项式系数按降幂排列所形成的向量. solve ...

  3. matlab求多项式的实数根_matlab中怎么求多项式的根

    2017-10-09 回答 用matlab解方程的三个实例 1.对于多项式p(x)=x3-6x2-72x-27,求多项式p(x)=0的根,可用多项式求根函数roots(p),其中p为多项式系数向量,即 ...

  4. matlab根号下是多项式,多项式求根

    本帖最后由 pengcsu 于 2016-6-12 12:45 编辑 小弟最近做实验过程中,得到x,y两列数据,数据处理需要得到整数的y对应的x值.但是实验实际测得的都是非整数的y.小弟的思路是对x, ...

  5. [学习笔记]多项式开根

    还是倍增思想 每一层 还要套一个多项式求逆 所以O(nlog^2n),常数也不小 数组比较多 再trick一下 得到: $T=(T'+F*inv(T'))*inv2$ 可以只算一次多项式求逆,一次NT ...

  6. CF438E The Child and Binary Tree 生成函数、多项式开根

    传送门 设生成函数\(C(x) = \sum\limits_{i=0}^\infty [\exists c_j = i]x^i\),答案数组为\(f_1 , f_2 , ..., f_m\),\(F( ...

  7. 洛谷 5205 【模板】多项式开根

    题目:https://www.luogu.org/problemnew/show/P5205 不会二次剩余. 牛顿迭代推开根式子: \( f^2(x)-g(x)=0 \) \( f(x)=f_0(x) ...

  8. java多项式和_在Java中查找多项式的根

    小编典典 请找到以下相同的示例示例 public class PolynomialRootFinder { /** * * Given a set of polynomial coefficients ...

  9. matlab roots 多项式实现 c语言,Matlab教学课apos;件教学教案.doc

    -_ Matlab 简易教程 前言 Matlab是matrix laboratory的缩写,是矩阵实验室的意思,它是一个功能强大的数学工具软件.Matlab的产生是与数学计算紧密联系在一起的,1980 ...

  10. pythonchar中的拟合方法_在python中利用numpy求解多项式以及多项式拟合的方法

    构建一个二阶多项式:x^2 - 4x + 3 多项式求解 >>> p = np.poly1d([1,-4,3]) #二阶多项式系数 >>> p(0) #自变量为0时 ...

最新文章

  1. pring Boot与MyBatista的集成
  2. php框架是不是累赘,PHP框架,伤不起啊,伤不起
  3. Chrome Inspect调试微信出现空白页面的解决方法
  4. XamarinSQLite教程在Xamarin.Android项目中提取数据库文件
  5. python下载大文件-python 大文件
  6. NormalMap 贴图 [转]
  7. 不使用JavaScript实现菜单的打开和关闭
  8. redis session java获取attribute_面试题:给我说说你能想到几种分布式session实现?...
  9. linux 端口 操作
  10. 最简单的基于FFmpeg的移动端例子:IOS HelloWorld
  11. SQL之间,MySQL在日期之间,而不是之间
  12. 了解单反相机的自动对焦点
  13. 脑机接口:互联网遥远的疆界
  14. java forward方法_JAVA的服务重定向:使用forward()方法转发请求和使用sendRedirect()方法重定向的区别...
  15. java计算机毕业设计民航售票管理系统源代码+数据库+系统+lw文档
  16. JavaScript删除节点
  17. dbv数据库乱码_使用DBV进行数据库版本控制
  18. 管理与维护linux系统(任务五 六 七 八)
  19. 学习论文写作课程的心得体会
  20. easyExcel的复杂表头多级表头导入

热门文章

  1. 常见服务器故障有哪些?如何预防服务器发生故障?服务器故障后如何恢复数据?
  2. Orcad Capture CIS出BOM表
  3. 特殊符号大全,方便大家输入特殊字符用
  4. 李开复给中国大学生的第五封信—你有选择的权利
  5. PS1045L-ASEMI肖特基二极管PS1045L正向压降怎么测
  6. 基于社会工程学的网络攻击手段分析
  7. python学而思和猿辅导哪个好_学而思和猿辅导哪个好,说说我的评价
  8. JS中的curry化(柯里化)
  9. linux ipcs字段含义 共享内存删除 ipcs dest状态
  10. Docker安装与常用命令详解——初步拓荒