#include <iostream>

int main() {
    long long l, r, b;
    std::cin >> std::hex >> l;
    std::cin >> std::hex >> r;
    std::cin >> std::hex >> b;

    int ans = 0;
    for (long long x = l; x <= r; ++x) {
        if ((x & b) == b) {
            ans += 1;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

