#include<bits/stdc++.h>
#include<string>
using namespace std;
#define rep(i,n) for(int i=1;i<n+1;i++)

int main(){
    int n;
    cin >> n;

    int sum=0;
    int a,b,c,r;
    for(int i=1;i<n+1;i++){
        a = i;
        for(int j=1;j<n+1;j++){
            int f = a;
            b = j;
            if (f<b) {
                int temp = b;
                b = f;
                f = temp;
            }
            while(f%b!=0){
               r = f % b;
                f = b;
                b = r;
            }
            for(int k=1;k<n+1;k++){
                int g = b;
                c = k;
                if (g>c){
                    int temp = c;
                    c = g;
                    g = temp;
                }
                while(c%g!=0){
                    r = c % g;
                    c = g;
                    g = r;
                }
                sum += g;
            }
        }
    }

    cout << sum << endl;;
    return 0;
}