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

12 -12 -454 -373 3754 1680
Sample Output

题意:给你一个首项为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-有理根

参考资料:

UVALive 7178 Irrational Roots 多项式的根的更多相关文章

  1. Gym 100818F Irrational Roots (数学)

    Irrational Roots http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101594#problem/F [题意]: 判断一个整系 ...

  2. Codeforces 250 E. The Child and Binary Tree [多项式开根 生成函数]

    CF Round250 E. The Child and Binary Tree 题意:n种权值集合C, 求点权值和为1...m的二叉树的个数, 形态不同的二叉树不同. 也就是说:不带标号,孩子有序 ...

  3. 【XSY2730】Ball 多项式exp 多项式ln 多项式开根 常系数线性递推 DP

    题目大意 一行有\(n\)个球,现在将这些球分成\(k\) 组,每组可以有一个球或相邻两个球.一个球只能在至多一个组中(可以不在任何组中).求对于\(1\leq k\leq m\)的所有\(k\)分别 ...

  4. 【BZOJ3625】【CF438E】小朋友和二叉树 NTT 生成函数 多项式开根 多项式求逆

    题目大意 考虑一个含有\(n\)个互异正整数的序列\(c_1,c_2,\ldots ,c_n\).如果一棵带点权的有根二叉树满足其所有顶点的权值都在集合\(\{c_1,c_2,\ldots ,c_n\ ...

  5. BZOJ3625 [Codeforces Round #250]小朋友和二叉树(生成函数+多项式开根)

    设f(n)为权值为n的神犇二叉树个数.考虑如何递推求这个东西. 套路地枚举根节点的左右子树.则f(n)=Σf(i)f(n-i-cj),cj即根的权值.卷积的形式,cj也可以通过卷上一个多项式枚举.可以 ...

  6. 【BZOJ3625】【codeforces438E】小朋友和二叉树 生成函数+多项式求逆+多项式开根

    首先,我们构造一个函数$G(x)$,若存在$k∈C$,则$[x^k]G(x)=1$. 不妨设$F(x)$为最终答案的生成函数,则$[x^n]F(x)$即为权值为$n$的神犇二叉树个数. 不难推导出,$ ...

  7. P5277 【模板】多项式开根(加强版)(bsgs or Cipolla)

    题面 传送门 题解 首先你得会多项式开根->这里 其次你得会解形如 \[x^2\equiv a \pmod{p}\] 的方程 这里有两种方法,一个是\(bsgs\)(这里),还有一种是\(Cip ...

  8. FFT模板 生成函数 原根 多项式求逆 多项式开根

    FFT #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> ...

  9. BZOJ 3625 [Codeforces Round #250]小朋友和二叉树 ——NTT 多项式求逆 多项式开根

    生成函数又有奇妙的性质. $F(x)=C(x)*F(x)*F(x)+1$ 然后大力解方程,得到一个带根号的式子. 多项式开根有解只与常数项有关. 发现两个解只有一个是成立的. 然后多项式开根.求逆. ...

随机推荐

  1. Scrapy爬虫-win7下创建运行项目

    开始的时候,我只安装了python3.5,安装不了scrapy库,网上搜了一下说是scrapy不支持python3.x 然后,我就又安装了python2.7 为了,默认使用2.7,我在环境变量path ...

  2. 第6章:使用Python监控Linux系统

    1.Python编写的监控工具 1).多功能系统资源统计工具dstat dstat是一个用Python编写的多功能系统资源统计工具,用来取代Linux下的vmstat,iostat,netstat和i ...

  3. T100——汇总错误消息显示

    初始化 CALL cl_err_collect_init() 汇总消息显示 CALL cl_err_collect_show()

  4. Spring Boot:上传文件大小超限制如何捕获 MaxUploadSizeExceededException 异常

    Spring Boot 默认上传文件大小限制是 1MB,默认单次请求大小是 10MB,超出大小会跑出 MaxUploadSizeExceededException 异常 spring.servlet. ...

  5. JS 验证字符串是否能转为json格式

    var isJSON=function (str) { if (typeof str == 'string') { try { var obj = JSON.parse(str); if (typeo ...

  6. python 读取文件行

    将文件转化成二进制码,并读取行数,计算总行数 import os Str=input("请输入路径") Sum=0 def read(Str): a = os.listdir(St ...

  7. 正则表达式split匹配多种例如 “】”,“,”两种(页面级中英文切换方案)

    在做登陆界面的时候,因为涉及到中英文 因为前后台已经分离,所以前端需要自行设计中英文 做法: 编写两个文件,一个中文文件,一个是英文文件,分别放在对应的目录下面 文件的内容 { "login ...

  8. vue 实现textarea展示时自动换行

    利用 v-html 展示 str.replace(/\n|\r\n/g, '<br>') 数据 完美解决

  9. Java后端开发常用工具

    Java后端开发常用工具推荐: 俗话说,工欲善其事,必先利其器.不过初学时候不大建议过度依赖IDE等过多工具,这会让自己的编程基础功变得很差,比如各种语法的不熟悉,各种关键字比如synchronize ...

  10. 1.JavaWeb 知识点概览

    1.tomcat服务器的安装和配置.http协议 1.1 虚拟目录的 /*映射*/(配置Context元素)(server.xml catalina\localhost\) http://blog.c ...