fork download
  1. //amazing takes time, legendary requires patience
  2. #include "bits/stdc++.h"
  3. #define sd(n) scanf("%d", &(n))
  4. #define rep(i, x, n) for (int i = x, _n = (n); i < _n; ++i)
  5. #define repi(i, a) for(typeof((a).begin()) i = (a).begin(), _##i = (a).end(); i != _##i; ++i)
  6. #define pra(v) repi(it, v) cout << *it << " "; cout << endl;
  7. #define SZ(c) (int)(c).size()
  8. #define lcm(a,b) (a*(b/__gcd(a,b)))
  9. #define VI vector<int>
  10. #define all(c) (c).begin(), (c).end()
  11. #define allr(c) (c).rbegin(), (c).rend()
  12. #define pb push_back
  13. #define mii map<int, int>
  14. #define pii pair<int, int>
  15. #define pip pair<int, pii>
  16. #define F first
  17. #define S second
  18. #define mp make_pair
  19. #define lli long long int
  20. #define llu unsigned long long
  21. #define CLR(p) memset(p, 0, sizeof(p))
  22. #define SET(p) memset(p, -1, sizeof(p))
  23. #define INF 0x3f3f3f3f
  24. #define pi 3.141592653589793
  25. #define debug 0
  26. using namespace std;
  27.  
  28. const int MOD = 1e9+7;
  29. const int MAX = 100010;
  30. const double eps = 1e-8;
  31.  
  32. lli n, m;
  33.  
  34. int main()
  35. {
  36. cin >> n >> m;
  37. double tmp = 0.0;
  38. if(n > 1)
  39. tmp = log(n-1)/log(7);
  40. lli nd = 1LL + int(tmp);
  41.  
  42. if(m > 1)
  43. tmp = log(m-1)/log(7);
  44. else
  45. tmp = 0.0;
  46. lli md = 1 + int(tmp);
  47. // cout << nd << " " << md << endl;
  48. if(nd + md > 7)
  49. {
  50. cout << 0 << endl;
  51. return 0;
  52. }
  53. lli cnt = 0;
  54. rep(i, 0, (1<<7))
  55. {
  56. VI v;
  57. rep(j, 0, 7)
  58. {
  59. if((1<<j)&i)
  60. v.pb(j);
  61. }
  62. if(SZ(v) != nd+md) continue;
  63. do
  64. {
  65. lli hr = 0, mi = 0;
  66. rep(i, 0, nd)
  67. hr = hr*7LL + v[i];
  68. rep(i, nd, SZ(v))
  69. mi = mi*7LL + v[i];
  70.  
  71. if(mi < m and hr < n)
  72. {
  73. // cout << hr << ":" << mi << endl;
  74. cnt++;
  75. }
  76. }while(next_permutation(all(v)));
  77. }
  78. cout << cnt << endl;
  79. return 0;
  80. }
Success #stdin #stdout 0s 3420KB
stdin
344 344
stdout
0