import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;

public class Main {

  public static void main(final String[] args) {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sum = 0;

    if (num == 1) {
      System.out.println('1');
      return;
    }

    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    }

    System.out.println(sum);
  }

  private static int gcd(int[] num) {
    int ans = num[0];

    for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    }
    return ans;
  }

  private static int func(int a, int b) {

    if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    }
  }
} import java.io.*; io.* java import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Queue; Queue java.util public class Main {

  public static void main(final String[] args) {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sum = 0;

    if (num == 1) {
      System.out.println('1');
      return;
    }

    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    }

    System.out.println(sum);
  }

  private static int gcd(int[] num) {
    int ans = num[0];

    for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    }
    return ans;
  }

  private static int func(int a, int b) {

    if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    }
  }
} Main public static void main(final String[] args) {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sum = 0;

    if (num == 1) {
      System.out.println('1');
      return;
    }

    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    }

    System.out.println(sum);
  } main {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sum = 0;

    if (num == 1) {
      System.out.println('1');
      return;
    }

    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    }

    System.out.println(sum);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int sum = 0; sum 0 if (num == 1) {
      System.out.println('1');
      return;
    } num == 1 num 1 {
      System.out.println('1');
      return;
    } System.out.println('1') System.out.println System.out System System.out '1' return; for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    } int i = 1; int i = 1; i 1 i <= num i num i++ i++ i {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    } {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    } for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      } int j = 1; int j = 1; j 1 j <= num j num j++ j++ j {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      } {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      } for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        } int k = 1; int k = 1; k 1 k <= num k num k++ k++ k {
          int[] test = {i, j, k};
          sum += gcd(test);
        } {
          int[] test = {i, j, k};
          sum += gcd(test);
        } int[] test = {i, j, k}; test {i, j, k} i j k sum += gcd(test) sum gcd(test) gcd test System.out.println(sum) System.out.println System.out System System.out sum final String[] args args private static int gcd(int[] num) {
    int ans = num[0];

    for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    }
    return ans;
  } gcd {
    int ans = num[0];

    for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    }
    return ans;
  } int ans = num[0]; ans num[0] num 0 for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    } int i = 1; int i = 1; i 1 i < num.length i num.length num num.length i++ i++ i {
      ans = func(ans, num[i]);
    } {
      ans = func(ans, num[i]);
    } ans = func(ans, num[i]) ans func(ans, num[i]) func ans num[i] num i return ans; ans int[] num num private static int func(int a, int b) {

    if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    }
  } func {

    if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    }
  } if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    } b != 0 b 0 {
      return func(b, a % b);
    } return func(b, a % b); func(b, a % b) func b a % b a b {
      return a;
    } return a; a int a a int b b public class Main {

  public static void main(final String[] args) {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sum = 0;

    if (num == 1) {
      System.out.println('1');
      return;
    }

    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    }

    System.out.println(sum);
  }

  private static int gcd(int[] num) {
    int ans = num[0];

    for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    }
    return ans;
  }

  private static int func(int a, int b) {

    if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    }
  }
} public class Main {

  public static void main(final String[] args) {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sum = 0;

    if (num == 1) {
      System.out.println('1');
      return;
    }

    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    }

    System.out.println(sum);
  }

  private static int gcd(int[] num) {
    int ans = num[0];

    for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    }
    return ans;
  }

  private static int func(int a, int b) {

    if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    }
  }
} Main
import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;

public class Main {

  public static void main(final String[] args) {

    Scanner sc = new Scanner(System.in);

    int num = sc.nextInt();
    int sum = 0;

    if (num == 1) {
      System.out.println('1');
      return;
    }

    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          int[] test = {i, j, k};
          sum += gcd(test);
        }
      }
    }

    System.out.println(sum);
  }

  private static int gcd(int[] num) {
    int ans = num[0];

    for (int i = 1; i < num.length; i++) {
      ans = func(ans, num[i]);
    }
    return ans;
  }

  private static int func(int a, int b) {

    if (b != 0) {
      return func(b, a % b);
    } else {
      return a;
    }
  }
}
