36: Calculate the polynomial value. 36: Calculate the polynomial.
36: Calculate the polynomial Value
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Assume that the polynomial form is xn + xn-1 +... + X2 + x + 1: calculate the value of this polynomial when given single-precision floating point number x and positive integer n.
-
Input
-
Enter only one line, including x and n, separated by a single space. X is in the float range, n <= 1000000.
-
Output
-
Output a real number, that is, the polynomial value, accurate to two digits after the decimal point. Ensure that the final result is within the float range.
-
Sample Input
-
2.0 4
-
Sample output
-
31.00
1 de<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 int main() 7 { 8 float x; 9 int n;10 float tot=0;11 cin>>x>>n;12 int a=n;13 for(int i=n;i>=1;i--)14 {15 tot=tot+pow(x,a);16 a--;17 }18 printf("%.2f",tot+1);19 return 0;20 }