#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
const ll mod = 10007;
using namespace std;
ll exgcd(ll a,ll b,ll& x,ll& y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
ll r = exgcd(b,a%b,x,y);
ll t = x%mod;
x = y%mod;
y = ((t-a/b*x)%mod+mod)%mod;
return r;
}
int main()
{
ll a;
while(1)
{
ll x;
ll y;
cin >> a;
exgcd(a,mod,x,y);
cout << x << endl;
}
return 0;
}
求逆元除此方法之外还可以用pow(a,mod-2)%mod来求。(前提是mod为质数且逆元存在)