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. public class Main {
  8.  
  9. // Function to count the number of digits in an integer
  10. public static int digit_count(int num) {
  11. return Integer.toString(num).length();
  12. }
  13.  
  14. public static void main(String[] args) {
  15. int n = 3;
  16. int[] b = {0, 3, 14, 15}; // Given input, using 0 to keep 1-based index
  17.  
  18. long sum = 0;
  19. long ans = 0;
  20.  
  21. for (int j = 1; j <= n; ++j) {
  22. int y = digit_count(b[j]);
  23. long vl = (j - 1) * b[j] + (long)Math.pow(10, y) * sum;
  24. ans += vl;
  25. sum += b[j]; // Update sum with the current b[j]
  26. }
  27.  
  28. System.out.println("Sum: " + ans);
  29. }
  30. }
  31.  
Success #stdin #stdout 0.16s 55664KB
stdin
Standard input is empty
stdout
Sum: 2044