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-有理根

参考资料:

最新文章

  1. app状态监听广播
  2. C/C++多种方法获取文件大小(转)
  3. File类的常用方法
  4. 【iCore2双核心板视频教程三】iM_LAN 100M 以太网模块TCP压力测试(更新视频教程)
  5. 【6.24-北京】AppCan移动开发者大会:最新议程曝光
  6. 如何优化C语言代码(程序员必读)
  7. android音乐播放器开发教程
  8. SSH服务
  9. BZOJ 1854 游戏
  10. Stream类
  11. NHibernate初入门之配置文件属性说明(四)
  12. VC/MFC 使edit控件不能进行粘贴操作
  13. ASP中文件上传组件ASPUpload介绍和使用方法
  14. contentHorizontalAlignment 属性浅析
  15. angular4.0配置本机IP访问项目
  16. Linux Mint(ubuntu)如何汉化firefox浏览器?
  17. 低版本Flume兼容高版本elasticsearch
  18. PHP工程师必备知识整理
  19. python实现将字符串中以大写字母开头的单词前面添加“_”下划线
  20. Spring Boot+Spring Security:获取用户信息和session并发控制

热门文章

  1. LC 387. First Unique Character in a String
  2. 火狐 , IE , 谷歌浏览器的 驱动下载地址汇总
  3. 第十二章 ZYNQ-MIZ702 PS读写PL端BRAM
  4. TCP协议探究(四):定时器
  5. MySQL修改和查看表类型
  6. Git 集成 Araxis Merge 作为比较和合并GUI工具的配置 参考自https://www.kancloud.cn/leviio/git/369125
  7. 微信小程使用getCurrentPages函数操作父级数据
  8. __imp__SetupDiDestroyDeviceInfoList
  9. ubuntu目录结构(转)
  10. bootstrap 处理警告