Gym 100818F Irrational Roots (数学)

 Irrational Roots

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101594#problem/F

 

【题意】:

判断一个整系数高阶方程的无理根的个数。

【解题思路】:

定理:如果方程f(x)=0的系数都是整数,那么方程有理根仅能是这样的分数p/q,其分子p是方程常数项的约数,分母q是方程最高次项的约数

这里最高次系数为1,那么有理根就一定为整数。

题目给定了根的范围,枚举整数判断是为根即可。

重根判断:求导直到导数不为0.

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #define LL long long
 7 #define maxn 1100000
 8 #define eps 1e-8
 9 #define IN freopen("in.txt","r",stdin);
10 using namespace std;
11 
12 int main(int argc, char const *argv[])
13 {
14     //IN;
15 
16     int n;
17     LL a[10];
18     LL b[10];
19     while(scanf("%d",&n)!=EOF)
20     {
21         for(int i=1;i<=n;i++) scanf("%I64d",&b[i]);b[0]=1;
22 
23         int ans = 0;
24         for(int i=-10;i<=10;i++){
25             for(int j=0;j<=n;j++) a[j]=b[j];
26             LL t[10] = {0};
27             LL x = 1;
28             for(int j=n;j>=0;j--){
29                 t[j] =  a[j]*x;
30                 x *= i;
31             }
32 
33             LL  sum = 0;
34             for(int j=0;j<=n;j++) sum+=t[j];
35 
36             if(sum == 0){
37                 ans++;
38                 for(int k=0;k<n;k++){//qiudao
39 
40                     for(int j=n;j>=0;j--){
41                         a[j] = a[j]*(n-j-k);
42                     }
43                     LL x = 1;
44                     for(int j=n-k-1;j>=0;j--){
45                         t[j] =  a[j]*x;
46                         x *= i;
47                     }
48 
49                     LL sum = 0;
50                     for(int j=0;j<=n-k-1;j++) sum += t[j];
51                     if(sum == 0) ans++;
52                     else break;
53                 }
54             }
55         }
56 
57         printf("%d
",n-ans);
58     }
59 
60     return 0;
61 }
原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5031595.html