const D = 24;
const L = 3;

function new64(n) {
    return [n % (1<<D), (n / (1<<D)) | 0, 0];
}

function mul64s(a, b) {
    var r = [];
    var x = 0;
    for (var i = 0; i < L; i++) {
        x = a[i] * b + x;
        r[i] = x % (1<<D);
        x = Math.floor(x / (1<<D));
    }
    return r;
}

function add64s(a, b) {
    var r = [];
    var x = b;
    for (var i = 0; i < L; i++) {
        x = a[i] + x;
        r[i] = x % (1<<D);
        x = Math.floor(x / (1<<D));
    }
    return r;
}

function cmp64(a, b) {
    for (var i = L-1; i >= 0; i--) {
        if (a[i] < b[i]) return -1;
        if (a[i] > b[i]) return 1;
    }
    return 0;
}

function add64(a, b) {
    var r = [];
    var x = 0;
    for (var i = 0; i < L; i++) {
        x = a[i] + b[i] + x;
        r[i] = x % (1<<D);
        x = Math.floor(x / (1<<D));
    }
    return r;
}

function sub64(a, b) {
    var r = [];
    var x = 0;
    for (var i = 0; i < L; i++) {
        x = a[i] - b[i] - x;
        var borrow = 0;
        while (x < 0) {
            x += (1<<D);
            borrow++;
        }
        r[i] = x % (1<<D);
        x = borrow;
    }
    return r;
}

function div64s(a, b) {
    var x = 0;
    for (var i = L-1; i >= 0; i--) {
        x = a[i] + x * (1<<D);
        a[i] = (x / b) | 0;
        x = x % b;
    }
    return x;
}

function copy64(a, b) {
    for (var i = 0; i < L; i++) {
        a[i] = b[i];
    }
}

function shiftL64(a) {
    const msb = [0, 0, (1<<(D-1))];
    var d = a;
    var r = 0;
    if (cmp64(a, msb) >= 0) {
        r = 1;
        d = sub64(a, msb);
    }
    var c = add64(d, d);
    copy64(a, c);
    return r;
}

function div64(a, b) {
    var d = new64(0);
    var x = a.slice();
    var r = new64(0);
    for (var i = 0; i < L*D; i++) {
        var bit = shiftL64(x);
        shiftL64(d);
        d = add64s(d, bit);
        var y = 0;
        if (cmp64(d, b) >= 0) {
            d = sub64(d, b);
            y = 1;
        }
        shiftL64(r);
        r = add64s(r, y);
    }
    return r;
}

function parse64(s) {
    const l = s.length;
    var a = new64(0);
    for (var i = 0; i < l; i++) {
        a = mul64s(a, 10);
        a = add64s(a, parseInt(s.substr(i, 1), 10));
    }
    return a;
}

function print64(a) {
    var s = "";
    var x = a.slice();
    while (cmp64(x, new64(0)) !== 0) {
        s += div64s(x, 10);
    }
    if (s === "") {
        s = "0";
    }
    console.log(s);
}

function divisors(a, x) {
    return add64s(div64(a, x), 1);
}

function solve(a, b, x) {
    return sub64(divisors(b, x), (cmp64(a, new64(1)) >= 0 ? divisors(sub64(a, new64(1)), x) : new64(0)));
}

function main(input) {
    const args = input.trim().split(' ');
    const a = parse64(args[0]);
    const b = parse64(args[1]);
    const x = parse64(args[2]);
    const c = solve(a, b, x);
    print64(c);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
