#include<stdio.h>

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void)
{
int sum,i,j,count,N;

while(scanf("%d",&N)&&N!=0){
count=0;
sum=0;
for(i=1;i<=N;i++){
sum+=i;
if(sum>=N){
break;
}
}

for(j=2;j<=i;j++){
jj=j;
nn=N;
a=gcd(nn,jj);
nn/=a;
jj/=a;
if(jj%2){
if(nn%jj==0){
count++;
}
} else {
if(nn%jj==1){
count++;
}
}
}



printf("%d\n",count);
}
return 0;
}