今天來解YKL31(UVA10268):498'
計算多項式的微分
並把x代進去,求多項式全部的和
就像下圖題目解釋的
coef=>a
n-i=>n
pow(x, n - i - 1)=>X的n次方
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int derivative(int x, const vector<int>& coef) {
int n = coef.size() - 1;
int result = 0;
for (int i = 0; i < n; i++) {
result += coef[i] * (n - i) * pow(x, n - i - 1);
}
return result;
}
int main() {
int x;
while (cin >> x) {
vector<int> coef;
int c;
while (cin >> c) {
coef.push_back(c);
if (cin.peek() == '\n' || cin.peek() == EOF) break;
}
cout << derivative(x, coef) << endl;
}
return 0;
}