fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner scanIn=new Scanner(System.in);
  13. int n, x;
  14.  
  15. n = scanIn.nextInt();
  16. x = scanIn.nextInt();
  17.  
  18. int a[] = new int[n + 1];
  19.  
  20. for (int i = n; i >= 0; --i) {
  21. a[i] = scanIn.nextInt(); //enter values of array
  22. }
  23.  
  24. int s = a[n];
  25.  
  26. for (int i = 1; i <= n; ++i) {
  27. s *= x;
  28. s += a[n - i];
  29. }
  30.  
  31. System.out.println("S = " + s);
  32. }
  33. }
Success #stdin #stdout 0.09s 2841600KB
stdin
1
5
2
1
stdout
S = 11