Advertisement
palmerstone

Dice

Nov 14th, 2011
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <limits>
  5. #include <vector>
  6. #include <cstdio>
  7. #include <cmath>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <cctype>
  11. #include <ctime>
  12.  
  13. using namespace std;
  14.  
  15. unsigned long long int ar[30][200];
  16.  
  17. unsigned long long int power(unsigned long long int x, unsigned long long int n)
  18. {
  19. int i, j, k;
  20. unsigned long long int z = 1;
  21. if (n == 0) return 1;
  22. else if (n == 1) return x;
  23. else if (n % 2 == 0) z = (power(x, (n / 2)) * power(x, (n / 2)));
  24. else z = x * power(x, ((n - 1) / 2)) * power(x, ((n - 1) / 2));
  25. return z;
  26. }
  27.  
  28. unsigned long long int GreatestCommonDivisor(unsigned long long int a, unsigned long long int b)
  29. {
  30. if (b == 0) return a;
  31. GreatestCommonDivisor(b, (a % b));
  32. }
  33.  
  34. int main()
  35. {
  36. int i, j, k, l, n;
  37. unsigned long long int x, y, z, a, b, c, d;
  38.  
  39. ar[1][0] = 0;
  40. for (i = 1; i <= 150; i++)
  41. {
  42. if (i <= 6) ar[1][i] = 1;
  43. else ar[1][i] = 0;
  44. }
  45.  
  46. for (n = 2; n <= 24; n++)
  47. {
  48. for (i = 0; i < n; i++) ar[n][i] = 0;
  49. for (; i <= (6 * n); i++)
  50. {
  51. x = 0;
  52. for (j = 1; j <= 6; j++)
  53. {
  54. l = i - j;
  55. y = ar[n - 1][l];
  56. x += y;
  57. }
  58. ar[n][i] = x;
  59. }
  60. for (; i <= 150; i++) ar[n][i] = 0;
  61. }
  62.  
  63. for (; ;)
  64. {
  65. scanf("%d %d", &n, &i);
  66. if (n == 0 && i == 0) break;
  67. x = power(6, n), y = 0;
  68. for (j = i; j <= (6 * n); j++) y += ar[n][j];
  69. z = GreatestCommonDivisor(y, x);
  70. y /= z, x /= z;
  71. if (x == 1 || y == 0) printf("%llu\n", y);
  72. else printf("%llu/%llu\n", y, x);
  73. }
  74. return 0;
  75. }
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement