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

int main(){
     int  k;
    cin>>k;
    long long int  count=0;
    for ( int  i = 1; i <= k; i++)
    {
        
      for (int h = 1; h <= k; h++)
      {
          for (int o = 1; o <= k; o++)
          {
              if(i==1 || h==1 || o==1){
                  count+=1;
                  
              }else{
              int a=i;int b= h; int c=o;
              while (b) { a %= b; swap(a, b); } 
              while (c) { a %= c; swap(a, c); } 
              count+=a;}
          }
          
        
      }
      
    }
    cout<< count <<endl;

}