#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
vector<ll> primes;
vector<ll> is_prime(1000001);
ll N=0;
ll ans2;
void solve()
{
ll k;
ll x = 0;
k = 999983;
ll ans=0, mn=1e9;
for (int i=0;i<N;i++)
{
ans+=k*primes[i];
if (k%primes[i]==0)
x=i;
if (primes[i]==is_prime[k])
break;
}
// for (int i=0;i<N;i++)
// {
// ans+=k*primes[i];
// if (!(k%primes[i]))
// break;
// }
x+=ans;
ans2 += ans % 10000;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll t;
int n=1e6;
for (int i=0;i<n;i++)
is_prime[i]=i;
is_prime[0] = is_prime[1] = -1;
for (ll i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (ll j = i * i; j <= n; j += i)
is_prime[j] = min(i, is_prime[j]);
}
}
for (int i=2;i<=n;i++)
if (is_prime[i]==i)
primes.push_back(i),N++;
t = 10000;
while(t--)
{
solve();
}
cout << ans2 << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZW5kbCAiXG4iCnZlY3RvcjxsbD4gcHJpbWVzOwp2ZWN0b3I8bGw+IGlzX3ByaW1lKDEwMDAwMDEpOwpsbCBOPTA7CmxsIGFuczI7CnZvaWQgc29sdmUoKQp7CiAgICBsbCBrOwogICAgbGwgeCA9IDA7CiAgICBrID0gOTk5OTgzOwogICAgbGwgYW5zPTAsIG1uPTFlOTsKICAgIGZvciAoaW50IGk9MDtpPE47aSsrKQogICAgewogICAgICAgIGFucys9aypwcmltZXNbaV07CiAgICAgICAgaWYgKGslcHJpbWVzW2ldPT0wKQogICAgICAgICAgICB4PWk7CiAgICAgICAgaWYgKHByaW1lc1tpXT09aXNfcHJpbWVba10pCiAgICAgICAgICAgIGJyZWFrOwogICAgfQogICAgLy8gZm9yIChpbnQgaT0wO2k8TjtpKyspCiAgICAvLyB7CiAgICAvLyAgICAgYW5zKz1rKnByaW1lc1tpXTsKICAgIC8vICAgICBpZiAoIShrJXByaW1lc1tpXSkpCiAgICAvLyAgICAgICAgIGJyZWFrOwogICAgLy8gfQogICAgeCs9YW5zOwogICAgYW5zMiArPSBhbnMgJSAxMDAwMDsKfQppbnQgbWFpbigpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCksIGNpbi50aWUoMCksIGNvdXQudGllKDApOwogICAgbGwgdDsKICAgIGludCBuPTFlNjsKICAgIGZvciAoaW50IGk9MDtpPG47aSsrKQogICAgICAgIGlzX3ByaW1lW2ldPWk7CiAgICBpc19wcmltZVswXSA9IGlzX3ByaW1lWzFdID0gLTE7CiAgICBmb3IgKGxsIGkgPSAyOyBpICogaSA8PSBuOyBpKyspIHsKICAgICAgICBpZiAoaXNfcHJpbWVbaV0pIHsKICAgICAgICAgICAgZm9yIChsbCBqID0gaSAqIGk7IGogPD0gbjsgaiArPSBpKQogICAgICAgICAgICAgICAgaXNfcHJpbWVbal0gPSBtaW4oaSwgaXNfcHJpbWVbal0pOwogICAgICAgIH0KICAgIH0KICAgIGZvciAoaW50IGk9MjtpPD1uO2krKykKICAgICAgICBpZiAoaXNfcHJpbWVbaV09PWkpCiAgICAgICAgICAgIHByaW1lcy5wdXNoX2JhY2soaSksTisrOwogICAgdCA9IDEwMDAwOwogICAgd2hpbGUodC0tKQogICAgewogICAgICAgIHNvbHZlKCk7CiAgICB9CiAgICBjb3V0IDw8IGFuczIgPDwgJ1xuJzsKICAgIHJldHVybiAwOwp9