fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. unsigned long long int n, a, answer;
  7. cin >> n >> a;
  8. if (a > 1)
  9. {
  10. answer = n*a;
  11. for(unsigned long long int i = n-1; i > 0; --i)
  12. answer = (answer+i)*a;
  13. }
  14. else
  15. answer = n*(n+1)/2;
  16. cout << answer;
  17. return 0;
  18. }
Success #stdin #stdout 0s 4392KB
stdin
1009 1
stdout
509545