想法: 1 由于所有a[i] 是不为0的整数 所以解x是整数
2 其次解是an的约数
3 分解a[n] 用多项式除法判断约数是否为整式的解
#include<cstdio> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; LL a[25]; LL b[25]; int n; bool isok(LL x) { for (int i=0;i<=n;i++) b[i]=a[i]; for (int i=1;i<=n;i++) { LL t1=b[i-1]; LL t2=t1*x; b[i]-=t2; } if (b[n]==0) return 1; else return 0; } int main () { while (scanf("%d",&n)!=EOF) { a[0]=1; for (int i=1;i<=n;i++) { scanf ("%lld",&a[i]); } LL sum=0; LL p=abs(a[n]); for (LL i=1;i*i<=p;i++) { if (p%i==0) { if (isok(i)) sum-=i; if (isok(-i)) sum+=i; if (i==a[n]/i) continue; if (isok(a[n]/i)) sum-=a[n]/i; if (isok(-a[n]/i)) sum+=a[n]/i; } } printf("%.2lf ",sum*1.00); } return 0; }