
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int k;
    cin >> k;
    ll sum =0;
    for (int a = 1; a <= k; a++){
        for (int b = 1; b <= k; b++){
            for (int c = 1; c <= k; c++){
                int s = min(a, min(b,c));
                for (int i = s; i >= 1; i--){
                    if ((a%i == 0)&&(b%i == 0)&&(c%i == 0)){
                        sum += i;
                        break;
                    }
                }
            }
        }
    }
    cout << sum;
    return 0;
}


