fork(1) download
  1. #include<iostream>
  2. #include<cmath>
  3. double binpow(double x, int n) {
  4. while (--n)
  5. x *= x;
  6. return x;
  7. }
  8. int main() {
  9. double a, s = 0;
  10. int n;
  11. std::cin >> n >> a;
  12. for (int i = 1; i <= n; i++)
  13. s += i * binpow(a, i);
  14. std::cout << std::abs(s) << std::endl;
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0s 2988KB
stdin
4 4
stdout
262948