#include<bits/stdc++.h>
using namespace std;

int gcd(int x,int y){
 int tmp;
 int r;
 if(x > y){
    tmp = x;
    x = y;
    y = tmp;
  }
  r = y % x;
  while(r!=0){
    y = x;
    x = r;
    r = y % x;
  }
  return x;
}

int main(){
    int K;
    cin >> K;
    int i,j,k,l,m;
    int ans =0;
    for(i=1;i<K+1;i++){
        for(j=1;j<K+1;j++){
            l=gcd(i,j);
            for(k=1;k<K+1;k++){
                m=gcd(k,l);
                ans += m;
            }
        }
    }
    cout << ans << endl;
}