Language: C++

#include <iostream>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
#define MAX_N 1000 + 16
#define MOD 1000003
typedef long long LL;
int
        dp_a[MAX_N][MAX_N],         // dp_a[i][j]??¨?????\A?????´????????????i???????°????j???A?????????????????°
        dp_b[MAX_N][MAX_N],         // dp_b[i][j]??¨?????\B?????´????????????i???????°????j???A?????????????????°
        dp[MAX_N];                  // dp[i]??¨??????i??????????????¶?????????????????°
int n, k;
LL ans, all;
LL inv[MAX_N];
 
// ?????§?±????????????? a??b ??? 1 (mod m)
void init_inverse()
{
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++)
        inv[i] = (MOD - (MOD / i) * inv[MOD % i] % MOD) % MOD;
}
 
void solve()
{
    memset(dp_a, 0, sizeof(dp_a));
    memset(dp_b, 0, sizeof(dp_b));
    memset(dp, 0, sizeof(dp));
    int a_sum = 1, b_sum = 0;
    if (k >= n)
    {
        k = n - 1;
        all = 2;
    }
    dp_a[1][1] = 1;
    dp_b[1][1] = 0;
 
    for (int i = 2; i <= n; i++)
    {
        dp_a[i][1] = b_sum; // ??\B?????´??\A????°????????????´?????????A
        dp_b[i][1] = a_sum; // ??\A?????´??\A????°????????????´?????????B
        swap(a_sum, b_sum);
        for (int j = 2; j <= k; j++)
        {
            dp_a[i][j] = dp_a[i - 1][j - 1];        // ??¨????°???????A
            a_sum = (a_sum + dp_a[i][j]) % MOD;
            dp_b[i][j] = dp_b[i - 1][j - 1];        // ??¨????°???????B
            b_sum = (b_sum + dp_b[i][j]) % MOD;
        }
    }
 
    // ???????????????dp_b[i][1~k]??????????¶?dp[i]?????????????°???????????°????????????????????????????????¶????k
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            dp[i] += dp_b[i][j];
            dp[i] %= MOD;
        }
    }
 
    // ????????\A?????´?????????????°?dp_b??????????±??????\
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < k; j++)
        {
            dp_b[i][j + 1] += dp_b[i][j];
            dp_b[i][j + 1] %= MOD;
        }
    }
 
    // ???????????¢???p???A?????£???????°????A???????¶????k-p?????????dp_b[i-p][0~k-p]???????????????
    for (int i = 1; i <= n; i++)
    {
        for (int p = 1; p <= min(i, k); p++)
        {
            dp[i] += dp_b[i - p][k - p];
            dp[i] %= MOD;
        }
    }
}
 
int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    init_inverse();
    while (~scanf("%d%d", &n, &k))// for AOJ use while (scanf("%d%d", &n, &k) , n)
    {
        ans = 0, all = 0;
        solve();
        for (int i = 0; i < n; i++)
        {
            ans += 2 * dp[gcd(i, n)];   // ?????¢AB
            ans %= MOD;
        }
        ans = ans * inv[n] % MOD;
        printf("%lld\n", (ans + all) % MOD);
    }
#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    system("out.txt");
#endif
    return 0;
}
///////////////////////////End Sub//////////////////////////////////
 
/**************************************************************
    Problem: 1436
    User: hankcs
    Language: C++
    Result: Accepted
    Time:76 ms
    Memory:9560 kb
****************************************************************/

Compiler output:
a.cc: In function 'void solve()':
a.cc:69:18: error: 'i' was not declared in this scope
   69 |             dp_b[i][j + 1] += dp_b[i][j];
      |                  ^