extern crate core;

use std::str::FromStr;
use std::fmt;
use std::cmp::Ordering;
use std::fmt::{Display, Error, Formatter};

struct Istream {
    line: Vec<String>,
    position: usize
}
type Parse<T: FromStr> = Result<T, T::Err>;
impl Istream {
    fn new() -> Istream {
        Istream {line:vec![], position: 0}
    }
    fn read_word(&mut self) -> &String {
        if self.position == self.line.len() {
            let mut line= String::new();
            std::io::stdin().read_line(&mut line).ok();
            self.line = line.split_whitespace().map(|x|x.to_string()).collect();
            self.position = 0
        }
        let result = &self.line[self.position];
        self.position += 1;
        result
    }
    fn read(&mut self) -> String {
        self.read_word().to_string()
    }
    fn get<T: FromStr>(&mut self) -> T {self.read_word().parse().ok().unwrap()}
    fn read_usize(&mut self) -> usize {self.get()}
    fn read_int(&mut self) -> i32 {self.get()}
    fn read_long(&mut self) -> i64 {self.get()}
    fn read_double(&mut self) -> f64 {self.get()}
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}

macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! assign_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        assign_all!(iter; $($n:$t),*);
    };
    ($iter:expr; ) => {};
    ($iter:expr; $n:ident:$t:ty) => {
        let $n: $t = $iter.next().unwrap().parse().ok().unwrap();
    };
    ($iter: expr; $n:ident:$t:ty, $($m:ident:$u:ty),*) => {
        let $n: $t = $iter.next().unwrap().parse().ok().unwrap();
        assign_all!($iter; $($m:$u),*);
    };
}
macro_rules! repeat {
    ($count:expr; $($statement:tt)+) => {
        for _ in 0 .. $count {
            $($statement)*
        }
    };
}

macro_rules! yields {
    ($count:expr; $block:block) => {{
        let mut vec = Vec::with_capacity($count);
        for _ in 0 .. $count {
            vec.push($block);
        }
        vec
    }}
}
macro_rules! array {
    ($factor: expr, ) => {$factor};
    ($factor: expr, $dimension: expr) => {{
        let size = $dimension;
        let mut vec = Vec::with_capacity(size);
        for _ in 0 .. size {
            vec.push(array!($factor, ))
        }
        vec
    }};
    ($factor:expr, $dimension:expr, $($r:expr),*) => {{
        let size = $dimension;
        let mut vec = Vec::with_capacity(size);
        for _ in 0 .. size{
            let factor = array!($factor, $($r),*);
            vec.push(factor)
        }
        vec
    }};
}
fn tabulate<F, R>(count: usize, mut generator: F) -> Vec<R> where F : FnMut(usize) -> R {
    let mut result = Vec::<R>::with_capacity(count);
    for f in 0..count {
        result.push(generator(f));
    }
    result
}

fn lower_bound<Predicate: Fn(usize) -> bool>(mut from:usize, mut to: usize, predicate: &Predicate) -> usize {
    while from < to {
        let mid = (from + to) / 2;
        if predicate(mid) {
            to = mid;
        }
        else {
            from = mid + 1;
        }
    }
    to
}
fn main() {
    loop {
        let_all!(n: usize);
        if n == 0 {
            break
        }
        let mut count = 0;
        for i in 2 .. (n + 3) / 2 {
            if i * (i + 1) / 2 >= n {
                let whole = i * (i + 1) / 2;
                let lower = lower_bound(0, i - 2,&|x|{ whole - x * (x + 1) / 2 <= n});
                if whole - (lower * (lower + 1) / 2) == n {
                    count += 1;
                }
            }
        }
        println!("{}", count);
    }
}


Measured memory_bytes: 5028