fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. long n = in.nextInt(), a = in.nextInt(), ans;
  11. if (a > 1)
  12. {
  13. ans = n*a;
  14. for(long i = n-1; i > 0; --i)
  15. ans = (ans+i)*a;
  16. }
  17. else
  18. ans = n*(n+1)/2;
  19. System.out.println(ans);
  20. }
  21. }
Success #stdin #stdout 0.1s 2841600KB
stdin
4 1
stdout
10