#include #include #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i=0; i--) using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); i64 N, M; cin >> N >> M; vector> T; i64 cycleTime = 1; rep(i,N) cycleTime *= 12; i64 cycleTime3 = 1; rep(i,N) cycleTime3 *= 3; i64 cycleTime4 = 1; rep(i,N) cycleTime4 *= 4; i64 cycleTime6 = 1; rep(i,N) cycleTime6 *= 6; using Modint = atcoder::modint; Modint::set_mod(cycleTime3); i64 MxInv = Modint(cycleTime4).inv().val(); rep(i,1<<30) if(i%3 == 0){ i64 t = i; vector dig; rep(n,N){ dig.push_back(t%3); t /= 3; } if(t) break; reverse(dig.begin(), dig.end()); i64 t3 = 0; for(i64 a : dig) t3 = t3 * 3 + a; i64 t4 = 0; for(i64 a : dig) t4 = t4 * 4 + a; i64 t6 = 0; for(i64 a : dig) t6 = t6 * 6 + a; i64 t12 = (t4 + (i64(Modint(MxInv * (t3 - t4)).val()) << (N*2))); i64 sl = (t12 + cycleTime6 - t6) % cycleTime6; T.push_back({ sl, t12 }); } sort(T.begin(), T.end()); i64 ans = 0; for(i64 l=0; l(r-l+1); for(i64 i=l; i= M+3) ans += 1; l = r; } cout << ans << endl; return 0; }