using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
struct Matrix {
ll mat[5][5];
int r, c;
void init(int r, int c) {
this->r = r, this->c = c;
memset(mat, 0, sizeof(mat));
}
void identity(){
for(int i = 0; i < r; i++)
mat[i][i] = 1;
}
};
Matrix operator * (const Matrix &a, const Matrix &b) {
Matrix c;
c.init(a.r, b.c);
for(int i = 0; i < a.r; i++)
for(int k = 0; k < a.c; k++)
if(a.mat[i][k])
for(int j = 0; j < b.c; j++)
c.mat[i][j] = (c.mat[i][j] + a.mat[i][k] * b.mat[k][j] % mod) % mod;
return c;
}
Matrix operator ^ (Matrix x, int n) {
Matrix res;
res.init(x.r, x.c), res.identity();
while(n) {
if(n & 1) res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
ll f(ll n){
if(n == 1) return 1;
else if(n == 2) return 3;
else if(n == 3) return 4;
else if(n == 4) return 7;
else{
Matrix a;
a.init(2, 2);
a.mat[0][0] = a.mat[0][1] = a.mat[1][0] = 1;
a = a ^ (n-2);
return (a.mat[0][0]*3+a.mat[0][1]*1)%mod;
}
}
ll quick_pow(ll x, ll n) {
ll res = 1;
x %= mod;
while(n) {
if(n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
vector<ll> divisors(ll n) {
vector<ll> res;
ll m = (ll)floor(sqrt(n * 1.0) + 0.5);
for(ll i = 1; i <= m; i++) {
if(n % i == 0) {
res.push_back(i);
if(i != n / i) res.push_back(n / i);
}
}
return res;
}
vector<ll> prime_factor(ll n) {
vector<ll> res;
ll m = (ll)floor(sqrt(n * 1.0) + 0.5);
for(ll i = 2; i <= m; i++) {
if(n % i == 0) {
res.push_back(i);
while(n % i == 0) n /= i;
}
}
if(n > 1) res.push_back(n);
return res;
}
ll euler_phi(ll n, const vector<ll> &prime)
{
ll res = n;
int m = prime.size();
for(int i = 0; i < m; i++) {
if(n % prime[i] == 0) {
res = res / prime[i] * (prime[i] - 1);
while(n % prime[i] == 0) n /= prime[i];
}
}
if(n>1) res=res/n*(n-1);
return res % mod;
}
ll polya(ll n) {
vector<ll> divs = divisors(n);
vector<ll> prime = prime_factor(n);
int m = divs.size();
ll ans = 0;
for(int i = 0; i < m; i++) {
ll euler = euler_phi(divs[i], prime);
ans += euler * f(n / divs[i]) % mod;
ans %= mod;
}
return ans * quick_pow(n, mod - 2) % mod;
}
int main(){
// freopen("input.txt","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
while(cin>>n) {
if(n == 1) {
printf("2\n");
continue;
}
ll ans = polya(n);
printf("%lld\n", ans);
}
return 0;
}