fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <math.h>
  5. #include <sstream>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. long long int x;
  11.  
  12. while (cin >> x)
  13. {
  14. string input;
  15. cin.ignore();
  16. getline(cin, input);
  17. vector<long long int> a;
  18.  
  19. stringstream ss(input);
  20.  
  21. long long int c;
  22.  
  23. while (ss >> c)
  24. a.insert(a.begin(), c);
  25.  
  26. long long int len = (long long int)a.size();
  27.  
  28. long long int ans = 0;
  29.  
  30. for (long long int i = 0; i < len; i++)
  31. ans += i * a[i] * (long long int)round(pow(x, (i - 1)));
  32.  
  33.  
  34. cout << ans << endl;
  35. }
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty