This page is still under construction.

Parts of this page are still being built. What you see may change.

Revenge of the Round Table

Time limit8sMemory limit512 MB

Summary
Count circular binary sequences of length n with no run of more than k equal symbols, modulo 1000003, up to rotation.
Level

Hard8 of 10

Topics
Combinatorics, Math, Dynamic programming, Number theory
Solved
No attempts yet

Problem

Two countries A and B have decided to hold a meeting to get acquainted. In total, n ambassadors from A and B will attend the meeting.

A round table is prepared for the meeting. The ambassadors are being seated at the round table, but they have agreed that, for deeper exchange, more than k ambassadors from the same country will not sit in a row.

Your task is to write a program that reports the number of possible arrangements when rotations are not counted as different. Your program should report that number modulo M = 1000003.

Here is an example. Suppose n = 4 and k = 2. When rotations are counted as different arrangements, the following six arrangements are possible.

AABB
ABBA
BBAA
BAAB
ABAB
BABA

However, when rotations are regarded as the same, the following two arrangements are possible.

AABB
ABAB

Therefore the program should report 2.

Input

The input consists of multiple datasets. Each dataset consists of two integers n (1 ≤ n ≤ 1000) and k (1 ≤ k ≤ 1000) on one line.

It does not always hold that k < n. This means the program should consider cases in which ambassadors from only one country attend the meeting.

The last dataset is followed by a line containing two zeros. This line is not part of any dataset and should not be processed.

Output

For each dataset, print the number of possible arrangements modulo M = 1000003 on one line.

Examples1

  1. Example 1

    Input
    3 1
    3 2
    3 3
    4 2
    10 5
    1000 500
    0 0
    
    Expected output
    0
    2
    4
    2
    90
    570682