#include <stdio.h>
int main(){
  int gcd(int p, int q) {
    while (q != 0) {
      int r = p % q;
      p = q; 
      q = r;
    }
    return p;
  }
  
int main(){
    int k;
    scanf("%d", &k);
    long sum = 0;
    
    for (int a = 1; a <= k; a++)
      for (int b = 1; b <= k; b++)
        for (int c = 1; c <= k; c++)
          sum += gcd(gcd(a, b), c);
    
    printf("%ld", sum);
    return 0;
 }