function Main(input){
    input = input.split("\n");


    var p = 2,prime = [],c = 0;

    while(p <= 123456 * 2){
        prime[c++] = p;
        while(1){
            p++;
            var fl = true;

            for(var i = 2;i < p;i++){
                if(p % i == 0){
                    fl = false;
                    break;
                }
            }

            if(fl)
                break;
        }
    }


    for(var i = 0;1;i++){
        var n = parseInt(input[i],10);

        if(n == 0)
            break;

        var start = -1,end;

        for(var j = 0;1;j++){
            if(start == -1 && prime[j] > n)
                start = j;
            if(start != -1 && prime[j] > 2 * n){
                end = j;
                break;
            }
        }
        console.log(end - start);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));