function Main(input){
    input = input.split("\n");
 
 
    var p = 1,prime = [],c = 1;

    prime[0] = 2;
 
    while(p <= 123456 * 2){
        while(1){
            p += 2;
            var fl = true;
 
            for(var i = 3;i <= Math.sqrt(p);i += 2){
                if(p % i == 0){
                    fl = false;
                    break;
                }
            }
 
            if(fl){
                prime[c++] = p;
                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"));