#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = {-1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1};
const int dy[] = {-1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1};
#define N 8010000
#define TC int t;cin>>t;while(t--)
void AIA(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
/*
             __               _____________                __                        _____________              __                ___        ___       ___________________________     ____        ____
            /\ \             |_____   _____|              /\ \                      |             |            /\ \              |   |      |   |     |                           |    \   \      /   /
           / /\ \                  | |                   / /\ \                     |   __________|           / /\ \             |   |      |   |     |      _____      _____     |     \   \    /   /
          / /  \ \                 | |                  / /  \ \                    |  |                     / /  \ \            |   |      |   |     |     |     |    |     |    |      \   \  /   /
         / /    \ \                | |                 / /    \ \                   |  |                    / /    \ \           |   |      |   |     |     |     |    |     |    |       \   \/   /
        / /      \ \               | |                / /      \ \                  |  |______             / /      \ \          |   |______|   |     |     |     |    |     |    |        \      /
       / /        \ \              | |               / /        \ \                 |         |           / /        \ \         |              |     |     |     |    |     |    |         \    /
      / /          \ \             | |              / /          \ \                |   ______|          / /          \ \        |    ______    |     |     |     |    |     |    |          |  |
     / /============\ \            | |             / /============\ \               |  |                / /============\ \       |   |      |   |     |     |     |    |     |    |          |  |
    / /==============\ \           | |            / /==============\ \              |  |               / /==============\ \      |   |      |   |     |     |     |    |     |    |          |  |
   / /                \ \          | |           / /                \ \             |  |              / /                \ \     |   |      |   |     |     |     |    |     |    |          |  |
  / /                  \ \    _____| |_____     / /                  \ \            |  |             / /                  \ \    |   |      |   |     |     |     |    |     |    |          |  |
 /_/                    \_\  |_____________|   /_/                    \_\ _________ |__|            /_/                    \_\   |___|      |___|     |_____|     |____|     |____|          |__|

                                                                      <<<<<<<<<<< NEVER GIVE UP !! >>>>>>>>>>>
                                                                    <<<<<<<< YOU CAN DO IT IF YOU WANT !! >>>>>>>>
                                                                     <<<<<<<<< BELIEVE IN YOURSELF !! >>>>>>>>>
*/
vector<ll>Ve;
set<ll>Se;
map<ll,ll>Mp;
deque<ll>De;
priority_queue<ll>Pe;
int main()
{
    AIA();
    ll s ,c=0;
    cin>>s;
    for(int i=1;i<=s;i++){
        for(int j=1;j<=s;j++){
            for(int y=1;y<=s;y++){
                    int d , e;
                    d = __gcd(i , j);
                    e = __gcd(d , y);
                c+=e;
            }
        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3648