import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt(); //繰り返す回数
    int a;  //割られる数＿最大公約数
    int b;  //割る数
    int c;  //あまり
    int max;  //最大公約数
    int sum = 0;

    for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    }
    System.out.println(sum);
  }
} import java.util.*; util.* java class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt(); //繰り返す回数
    int a;  //割られる数＿最大公約数
    int b;  //割る数
    int c;  //あまり
    int max;  //最大公約数
    int sum = 0;

    for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    }
    System.out.println(sum);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt(); //繰り返す回数
    int a;  //割られる数＿最大公約数
    int b;  //割る数
    int c;  //あまり
    int max;  //最大公約数
    int sum = 0;

    for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    }
    System.out.println(sum);
  } main {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt(); //繰り返す回数
    int a;  //割られる数＿最大公約数
    int b;  //割る数
    int c;  //あまり
    int max;  //最大公約数
    int sum = 0;

    for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    }
    System.out.println(sum);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int a; a int b; b int c; c int max; max int sum = 0; sum 0 for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    } {
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    } for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      } {
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      } for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        } int l=1; int l=1; l 1 l<=k l k l++ l++ l {
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        } {
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        } if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          } i>j i j {
            a = i;
            b = j;
            c = 1;
          } a = i a i b = j b j c = 1 c 1 {
            a = j;
            b = i;
            c = 1;
          } a = j a j b = i b i c = 1 c 1 while(c!=0){
            c = a%b;
            a = b;
            b = c;
          } c!=0 c 0 {
            c = a%b;
            a = b;
            b = c;
          } c = a%b c a%b a b a = b a b b = c b c max = a max a if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          } max>l max l {
            a = max;
            b = l;
            c = 1;
          } a = max a max b = l b l c = 1 c 1 {
            a = l;
            b = max;
            c = 1;
          } a = l a l b = max b max c = 1 c 1 while(c!=0){
            c = a%b;
            a = b;
            b = c;
          } c!=0 c 0 {
            c = a%b;
            a = b;
            b = c;
          } c = a%b c a%b a b a = b a b b = c b c max = a max a sum = sum+max sum sum+max sum max System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt(); //繰り返す回数
    int a;  //割られる数＿最大公約数
    int b;  //割る数
    int c;  //あまり
    int max;  //最大公約数
    int sum = 0;

    for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          if(i>j){
            a = i;
            b = j;
            c = 1;
          }else{
            a = j;
            b = i;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          if(max>l){
            a = max;
            b = l;
            c = 1;
          }else{
            a = l;
            b = max;
            c = 1;
          }       
          while(c!=0){
            c = a%b;
            a = b;
            b = c;
          }
          max = a;
          sum = sum+max;
        }
      }
    }
    System.out.println(sum);
  }
}