fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. static HashMap<Long, Long> hmap = new HashMap<>();
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner scanner = new Scanner(System.in);
  10. int testcases = scanner.nextInt();
  11.  
  12. for(int t =0; t <testcases; t++){
  13. long n = scanner.nextLong();
  14. System.out.println(maxDollars(n));
  15. }
  16.  
  17. scanner.close();
  18. }
  19.  
  20. private static long maxDollars(long n){
  21. // System.out.println(n);
  22. if(n < 12){
  23. return n;
  24. }
  25.  
  26. if(hmap.containsKey(n)){
  27. return hmap.get(n);
  28. }
  29.  
  30. long ans = Math.max(n, (maxDollars(n/2) + maxDollars(n/3) + maxDollars(n/4)));
  31. hmap.put(n, ans);
  32. return ans;
  33. }
  34. }
Success #stdin #stdout 0.12s 51832KB
stdin
1
12
stdout
13