import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  }
  
  private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  }
  
  private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  }
} Main public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  } main {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int k = Integer.parseInt(br.readLine()); k Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br long sum = 0L; sum 0L for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      } int i = 1; int i = 1; i 1 i <= k i k i++ i++ i for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      } for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      } int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      } {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      } int g = gcd(i, j); g gcd(i, j) gcd i j for (int s = 1; s <= k; s++)
          sum += gcd(g, s); int s = 1; int s = 1; s 1 s <= k s k s++ s++ s sum += gcd(g, s); sum += gcd(g, s) sum gcd(g, s) gcd g s System.out.print(sum) System.out.print System.out System System.out sum String[] args args private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  } gcd {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  } while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    } b != 0 b 0 {
      int t = b;
      b = a % b;
      a = t;
    } int t = b; t b b = a % b b a % b a b a = t a t return a; a int a a int b b public class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  }
  
  private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  }
} public class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  }
  
  private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) {
        int g = gcd(i, j);
        for (int s = 1; s <= k; s++)
          sum += gcd(g, s);
      }
    
    System.out.print(sum);
  }
  
  private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  }
}
