fork(1) download
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. import java.util.stream.LongStream;
  4.  
  5. class Ideone
  6. {
  7. public static void main(String[] args)
  8. {
  9. Scanner in = new Scanner(System.in);
  10. while (in.hasNextInt())
  11. {
  12. int x = in.nextInt();
  13. int y = in.nextInt();
  14. long[] n = calc(x, y);
  15. long sum = LongStream.of(n).sum();
  16. System.out.printf("x=%d, y=%d%n", x, y);
  17. System.out.println("出目 出現回数 出現率");
  18. System.out.println("---- -------- ------");
  19. for(int i = 0; i < n.length; i++)
  20. {
  21. System.out.printf("% 4d % 8d % 4.2f%n", i + y, n[i], n[i] * 100d / sum);
  22. }
  23. System.out.println();
  24. }
  25. }
  26.  
  27. static long[] calc(int x, int y)
  28. {
  29. long[] ary = new long[x];
  30. Arrays.fill(ary, 1);
  31.  
  32. while (--y > 0)
  33. {
  34. long[] next = new long[ary.length + x - 1];
  35. long num = 0;
  36. for (int i = 0; i < next.length; i++)
  37. {
  38. long add = i < ary.length ? ary[i] : 0;
  39. long sub = i - x >= 0 ? ary[i - x] : 0;
  40. num += add - sub;
  41. next[i] = num;
  42. }
  43. ary = next;
  44. }
  45. return ary;
  46. }
  47. }
Success #stdin #stdout 0.18s 4386816KB
stdin
6 3
10 10
stdout
x=6, y=3
出目 出現回数 出現率
---- -------- ------
   3        1  0.46
   4        3  1.39
   5        6  2.78
   6       10  4.63
   7       15  6.94
   8       21  9.72
   9       25  11.57
  10       27  12.50
  11       27  12.50
  12       25  11.57
  13       21  9.72
  14       15  6.94
  15       10  4.63
  16        6  2.78
  17        3  1.39
  18        1  0.46

x=10, y=10
出目 出現回数 出現率
---- -------- ------
  10        1  0.00
  11       10  0.00
  12       55  0.00
  13      220  0.00
  14      715  0.00
  15     2002  0.00
  16     5005  0.00
  17    11440  0.00
  18    24310  0.00
  19    48620  0.00
  20    92368  0.00
  21   167860  0.00
  22   293380  0.00
  23   495220  0.00
  24   810040  0.01
  25  1287484  0.01
  26  1992925  0.02
  27  3010150  0.03
  28  4443725  0.04
  29  6420700  0.06
  30  9091270  0.09
  31  12628000  0.13
  32  17223250  0.17
  33  23084500  0.23
  34  30427375  0.30
  35  39466306  0.39
  36  50402935  0.50
  37  63412580  0.63
  38  78629320  0.79
  39  96130540  0.96
  40  115921972  1.16
  41  137924380  1.38
  42  161963065  1.62
  43  187761310  1.88
  44  214938745  2.15
  45  243015388  2.43
  46  271421810  2.71
  47  299515480  3.00
  48  326602870  3.27
  49  351966340  3.52
  50  374894389  3.75
  51  394713550  3.95
  52  410820025  4.11
  53  422709100  4.23
  54  430000450  4.30
  55  432457640  4.32
  56  430000450  4.30
  57  422709100  4.23
  58  410820025  4.11
  59  394713550  3.95
  60  374894389  3.75
  61  351966340  3.52
  62  326602870  3.27
  63  299515480  3.00
  64  271421810  2.71
  65  243015388  2.43
  66  214938745  2.15
  67  187761310  1.88
  68  161963065  1.62
  69  137924380  1.38
  70  115921972  1.16
  71  96130540  0.96
  72  78629320  0.79
  73  63412580  0.63
  74  50402935  0.50
  75  39466306  0.39
  76  30427375  0.30
  77  23084500  0.23
  78  17223250  0.17
  79  12628000  0.13
  80  9091270  0.09
  81  6420700  0.06
  82  4443725  0.04
  83  3010150  0.03
  84  1992925  0.02
  85  1287484  0.01
  86   810040  0.01
  87   495220  0.00
  88   293380  0.00
  89   167860  0.00
  90    92368  0.00
  91    48620  0.00
  92    24310  0.00
  93    11440  0.00
  94     5005  0.00
  95     2002  0.00
  96      715  0.00
  97      220  0.00
  98       55  0.00
  99       10  0.00
 100        1  0.00