// Arup Guha
// 7/23/2012
// Solution to 2010 Southeast Regional Problem: Bitcounting

import java.util.*;

public class b {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		// Solve and store simple cases.
		int[] table = new int[64];
		for (int i=1; i<table.length; i++)
			table[i] = solveBF(i);

		long low = stdin.nextLong();
		long high = stdin.nextLong();
		int k = stdin.nextInt();

		// Solve each case.
		while (low != 0) {
			System.out.println(answer(low, high,table, k));
			low = stdin.nextLong();
			high = stdin.nextLong();
			k = stdin.nextInt();
		}
	}

	// Use brute force to figure out k(value).
	public static int solveBF(int value) {
		if (value == 1) return 0;
		int numbits = 0;
		while (value > 0) {
			numbits += (value%2);
			value = value/2;
		}
		return 1 + solveBF(numbits);
	}

	// Returns the highest power of 2 <= value.
	public static int findmsb(long value) {

		if (value < 2) return 0;
		long ans = 1;
		int shift = 0;
		while (ans <= value/2) {
			ans = ans << 1;
			shift++;
		}
		return shift;
	}

	// Returns n choose k.
	public static long combo(int n, int k) {

		if (n < k) return 0;
		if (k == 0) return 1;

		// To reduce our work.
		if (k > n/2) k = n - k;

		long answer = 1;
		for (int i=1; i<=k; i++)
			answer = answer*(n-i+1)/i;
		return answer;
	}

	// Returns the number of positive integers <= LIMIT with exactly bits number
	// of ones in their binary representation.
	public static long solve(long LIMIT, int bits) {

		int start = findmsb(LIMIT);

		// Simple base cases.
		if (LIMIT == 0 && bits > 0) return 0;
		if (bits > start+1) return 0;
		if (bits == 0) return 1;

		// This is the key to our solution.

		// If we set the msb to 0,
		// then we must choose any of the bits number of remaining bits to set to 1.

		// Alternatively, set the msb to 1, and then find the number of solutions with
		// that bit turned off that are less than the number formed by subtracting out
		// that msb.
		return combo(start, bits) + solve(LIMIT - (1L << start), bits-1);
	}

	public static long answer(long LIMIT, int[] table, int k) {

		if (k == 0) return 1;

		// The key here is to see which values we need to reduce to in our
		// table to obtain an answer of k. For each of these, add up how many
		// answers in our range map to this value.
		long ans = 0;
		for (int i=1; i<table.length; i++) {
			if (table[i] == k-1) {
				ans += solve(LIMIT, i);

				// This subtracts out counting 1, which should not be added.
				if (k == 1) ans--;
			}
		}

		// This is the sum of all of these.
		return ans;
	}

	// Since we want answers for a range instead of starting in the beginning.
	public static long answer(long start, long end, int[] table, int k) {

		if (start == 1)
			return answer(end, table, k);
		return answer(end, table, k) - answer(start-1, table, k);
	}
}