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. Python 面向对象编程详解

    Python 的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承.Py ...

  2. Oracle练习(一)

    Oracle 1.检索部门编号.部门名称.部门所在地及其每个部门的员工总数. select d.deptno,d.dname,d.loc,count(*) from emp e,dept d wher ...

  3. Web API 接口版本控制 SDammann.WebApi.Versioning

    前言 在设计对外 Web API 时,实务上可能会有新旧版本 API 并存的情况,例如开放 Web API 给厂商串接,但同一个服务更新版本时,不一定所有厂商可以在同一时间都跟着更新他们的系统,但如果 ...

  4. 安装HAXM报错:failed to configure driver unknown error. failed to open driver 并提示数字签证不可用

    1.安装微软补丁:https://www.microsoft.com/en-us/download/confirmation.aspx?id=46148 2.重启后重新安装HAXM

  5. intellij IDE 破解 简单 License server 法

    http://idea.iteblog.com/key.php

  6. SP338ROADS题解--最短路变式

    题目链接 https://www.luogu.org/problemnew/show/SP338 分析 联想到不久前做过的一道题\(Full\) \(Tank\),感觉可以用优先队列做,于是写了\(d ...

  7. Centos7--从最小化系统发开发环境

    Centos7--从最小化系统发开发环境 ​程序员总是离不开"环境"的困扰,从进入新手村的那一天就开始手动搞各种环境.虽然阿里云学生服务很方便,但是想弄集群真的买不起.正好实验室有 ...

  8. JDK + Tomcat 安装 + 制作自定义镜像【第 3 篇 系统镜像】

    [第 1 篇 JDK]:https://www.cnblogs.com/del88/p/11842387.html[第 2 篇 Tomcat]:https://www.cnblogs.com/del8 ...

  9. 小程序wxs是作用

    wxs weixin script,小程序的脚本语言:可以结合wxml构建页面结构: 说白了 就是在小程序里面写函数表达式的地方: wxml里面直接使用wxs,有错误再次刷新就能解决 <wxs ...

  10. 在cmd下import cv2报错——OpenCV实现BRISK

    平台:win10 x64 +JetBrains PyCharm 2018.2.4 x64 +Anaconda3(python3.7.0+opencv3.4.5) Issue说明:同学发了个python ...