#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,K,sum=0;
  cin >> K ;
  
  for(a=1;a<K+1;a++){
    for(b=1;b<K+1;b++){
      for(c=1;c<K+1;c++){
        if(gcd(a,gcd(b,c))==0)
          sum=sum+1;
        else
        sum=sum+gcd(a,gcd(b,c));
      }
    }
  }
    cout << sum <<endl;
}  