decimal/Decimal_artur.java

  1 import java.util.Scanner;
  2 
  3 public class Decimal_artur {
  4   public static void main(String[] args) {
  5     Scanner in = new Scanner(System.in);
  6 
  7     int n = 5001;
  8     int[] a = new int[n];
  9     for (int i = 1, j = 0; i < n; i++) {
 10       a[i] = a[i - 1] + dif[j];
 11       if (--rep[j] == 0)
 12         j++;
 13     }
 14 
 15     for (n = in.nextInt(); n != 0; n = in.nextInt())
 16       System.out.println(a[n]);
 17   }
 18 
 19   static int[] dif = new int[] { 1, 2, 0, 1, 4, 0, 1, 0, 9, 0, 2, 0, 4, 0, 6, 0, 18, 0, 12, 0, 2, 0, 36, 0, 12, 0, 4, 0, 18, 0,
 20       18, 0, 18, 0, 12, 0, 2, 0, 12, 0, 30, 0, 6, 0, 4, 0, 24, 0, 6, 0, 6, 0, 4, 0, 40, 0, 24, 0, 6, 0, 24, 0, 12, 0, 4, 0, 6,
 21       0, 30, 0, 14, 0, 28, 0, 26, 0, 4, 0, 8, 0, 4, 0, 6, 0, 32, 0, 30, 0, 6, 0, 16, 0, 26, 0, 28, 0, 12, 0, 42, 0, 8, 0, 18,
 22       0, 16, 0, 68, 0, 10, 0, 2, 0, 34, 0, 6, 0, 24, 0, 50, 0, 4, 0, 12, 0, 18, 0, 6, 0, 6, 0, 36, 0, 2, 0, 12, 0, 18, 0, 12,
 23       0, 6, 0, 18, 0, 4, 0, 6, 0, 6, 0, 6, 0, 44, 0, 18, 0, 10, 0, 12, 0, 24, 0, 6, 0, 6, 0, 30, 0, 32, 0, 6, 0, 4, 0, 2, 0,
 24       24, 0, 40, 0, 14, 0, 48, 0, 4, 0, 14, 0, 40, 0, 44, 0, 12, 0, 6, 0, 4, 0, 14, 0, 4, 0, 8, 0, 4, 0, 24, 0, 12, 0, 2, 0,
 25       42, 0, 34, 0, 12, 0, 32, 0, 36, 0, 6, 0, 6, 0, 22, 0, 12, 0, 24, 0, 14, 0, 12, 0, 40, 0, 36, 0, 30, 0, 38, 0, 12, 0, 34,
 26       0, 6, 0, 30, 0, 14, 0, 24, 0, 4, 0, 2, 0, 10, 0, 26, 0, 28, 0, 14, 0, 30, 0, 18, 0, 4, 0, 24, 0, 12, 0, 30, 0, 2, 0, 30,
 27       0, 12, 0, 6, 0, 22, 0, 6, 0, 6, 0, 24, 0, 12, 0, 14, 0, 66, 0, 4, 0, 6, 0, 30, 0, 14, 0, 24, 0, 4, 0, 12, 0, 24, 0, 6, 0,
 28       24, 0, 12, 0, 14, 0, 18, 0, 10, 0, 12, 0, 14, 0, 10, 0, 12, 0, 30, 0, 14, 0, 18, 0, 10, 0, 26, 0, 10, 0, 6, 0, 6, 0, 18,
 29       0, 12, 0, 32, 0, 40, 0, 8, 0, 4, 0, 114, 0, 30, 0, 54, 0, 30, 0, 6, 0, 2, 0, 40, 0, 2, 0, 12, 0, 18, 0, 12, 0, 28, 0, 18,
 30       0, 18, 0, 26, 0, 28, 0, 2, 0, 6, 0, 58, 0, 12, 0, 32, 0, 10, 0, 12, 0, 14, 0, 10, 0, 6, 0, 36, 0, 14, 0, 28, 0, 8, 0, 18,
 31       0, 40, 0, 12, 0, 42, 0, 12, 0, 14, 0, 16, 0, 80, 0, 24, 0, 22, 0, 18, 0, 12, 0, 32, 0, 6, 0, 16, 0, 18, 0, 8, 0, 28, 0,
 32       12, 0, 14, 0, 24, 0, 34, 0, 6, 0, 2, 0, 10, 0, 30, 0, 2, 0, 66, 0, 10, 0, 2, 0, 10, 0, 72, 0, 2, 0, 24, 0, 4, 0, 6, 0, 6,
 33       0, 104, 0, 16, 0, 68, 0, 22, 0, 18, 0, 12, 0, 80, 0, 10, 0, 24, 0, 114, 0, 6, 0, 6, 0, 24, 0 };
 34   static int[] rep = new int[] { 1, 2, 2, 1, 1, 6, 1, 2, 1, 1, 1, 3, 1, 5, 1, 17, 1, 11, 1, 1, 1, 35, 1, 11, 1, 3, 1, 17, 1,
 35       17, 1, 17, 1, 11, 1, 1, 1, 11, 1, 29, 1, 5, 1, 3, 1, 23, 1, 5, 1, 5, 1, 19, 1, 23, 1, 23, 1, 23, 1, 5, 1, 11, 1, 3, 1, 5,
 36       1, 29, 1, 13, 1, 27, 1, 25, 1, 3, 1, 7, 1, 3, 1, 5, 1, 31, 1, 29, 1, 5, 1, 15, 1, 25, 1, 27, 1, 11, 1, 41, 1, 7, 1, 17,
 37       1, 15, 1, 67, 1, 9, 1, 1, 1, 33, 1, 5, 1, 23, 1, 49, 1, 3, 1, 11, 1, 17, 1, 5, 1, 5, 1, 35, 1, 1, 1, 11, 1, 17, 1, 11, 1,
 38       5, 1, 17, 1, 3, 1, 5, 1, 5, 1, 5, 1, 43, 1, 17, 1, 9, 1, 11, 1, 23, 1, 5, 1, 5, 1, 29, 1, 31, 1, 5, 1, 3, 1, 1, 1, 23, 1,
 39       39, 1, 13, 1, 47, 1, 3, 1, 13, 1, 39, 1, 43, 1, 11, 1, 5, 1, 3, 1, 13, 1, 3, 1, 7, 1, 3, 1, 23, 1, 11, 1, 1, 1, 41, 1,
 40       33, 1, 11, 1, 31, 1, 35, 1, 5, 1, 5, 1, 21, 1, 11, 1, 23, 1, 13, 1, 11, 1, 39, 1, 35, 1, 29, 1, 37, 1, 11, 1, 33, 1, 5,
 41       1, 29, 1, 13, 1, 23, 1, 3, 1, 1, 1, 9, 1, 25, 1, 27, 1, 13, 1, 29, 1, 17, 1, 3, 1, 23, 1, 11, 1, 29, 1, 1, 1, 29, 1, 11,
 42       1, 5, 1, 21, 1, 5, 1, 5, 1, 23, 1, 11, 1, 13, 1, 65, 1, 3, 1, 5, 1, 29, 1, 13, 1, 23, 1, 3, 1, 11, 1, 23, 1, 5, 1, 23, 1,
 43       11, 1, 13, 1, 17, 1, 9, 1, 11, 1, 13, 1, 9, 1, 11, 1, 29, 1, 13, 1, 17, 1, 9, 1, 25, 1, 9, 1, 5, 1, 5, 1, 17, 1, 11, 1,
 44       31, 1, 39, 1, 7, 1, 3, 1, 113, 1, 29, 1, 53, 1, 29, 1, 5, 1, 1, 1, 39, 1, 1, 1, 11, 1, 17, 1, 11, 1, 27, 1, 17, 1, 17, 1,
 45       25, 1, 27, 1, 1, 1, 5, 1, 57, 1, 11, 1, 31, 1, 9, 1, 11, 1, 13, 1, 9, 1, 5, 1, 35, 1, 13, 1, 27, 1, 7, 1, 17, 1, 39, 1,
 46       11, 1, 41, 1, 11, 1, 13, 1, 15, 1, 79, 1, 23, 1, 21, 1, 17, 1, 11, 1, 31, 1, 5, 1, 15, 1, 17, 1, 7, 1, 27, 1, 11, 1, 13,
 47       1, 23, 1, 33, 1, 5, 1, 1, 1, 9, 1, 29, 1, 1, 1, 65, 1, 9, 1, 1, 1, 9, 1, 71, 1, 1, 1, 23, 1, 3, 1, 5, 1, 5, 1, 103, 1,
 48       15, 1, 67, 1, 21, 1, 17, 1, 11, 1, 79, 1, 9, 1, 23, 1, 113, 1, 5, 1, 5, 1, 23, 1, 33 };
 49 }