#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;



unsigned euclidean_gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main(){
    int n;
    cin>>n;
    long sum=0;

    int a,b,c;

    for(a=1;a<=n;a++){
        for(b=1;b<=n;b++){
            for(c=1;c<=n;c++){
                sum+=euclidean_gcd(euclidean_gcd(a,b),c);
            }
        }
    }
    cout<<sum<<endl;
    return 0;

}

