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. C语言中的#ifndef、#def、#endif等宏
  2. 雷军做程序员时写的博客,太牛了。。
  3. ASP.NET MVC 使用Log4Net记录系统运行中问题
  4. 手机java做贪吃蛇_如何用Java写一个贪吃蛇游戏
  5. .net mvc + layui做图片上传(二)—— 使用流上传和下载图片
  6. 2017 开发者大调查活动获奖名单新鲜出炉
  7. 学前儿童语言教育模拟试卷c卷,学前儿童语言教育模拟试卷参考答案.doc
  8. mysql 远程虚拟主机_navicat 远程连接虚拟机MYSQL数据库
  9. 计算机二级科目有ps吗,计算机二级有ps吗
  10. pythonwin下载中文版_Python官方下载 v3.9.0中文版_Win10镜像官网
  11. Flutter 入门安装——C#程序喵的Flutter之旅
  12. audio-音频标签
  13. 新中大财务软件服务器路径修改,新中大软件最常用的操作手册
  14. 利率交換 IRS 估值 (1) 前言
  15. SVN Eclipse插件Subclipse安装和配置
  16. Ubuntu 20.04 安装 Seismic Unix
  17. SQL基础整理(四) 数据的插入,删除和更新,以及事物
  18. Wampserver 80端口被占用
  19. 美团校招年薪35万!老员工薪资倒挂,如何应对?
  20. Equalize the Remainders(思维)

热门文章

  1. linux和windows局域网连接网络,linux与windows局域网互访
  2. 互联网大数据项目汇报计划书PPT模板
  3. 咪咕阅读怎么下载小说
  4. 为什么程序员从来不炫富?
  5. 基于CentOS 6.10的Oracle 11g RAC安装手册
  6. ES6 Symbol基本用法
  7. CocCocoa Touch框架和Cocoa
  8. DECOUPLED WEIGHT DECAY REGULARIZATION
  9. iOS滤镜实现之LOMO(美图秀秀经典LOMO)
  10. python 表格处理项目该如何分工_python 处理 Excel 表格