import java.util.*;
public class Main {
  
  public static int gcd2(int i, int j){
    if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    }
  }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    }
    
    System.out.println(sum);
  }
} import java.util.*; util.* java public class Main {
  
  public static int gcd2(int i, int j){
    if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    }
  }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    }
    
    System.out.println(sum);
  }
} Main public static int gcd2(int i, int j){
    if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    }
  } gcd2 {
    if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    }
  } if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    } i == 0 i 0 {
      return j;
    } return j; j {
      return gcd2(j%i, i);
    } return gcd2(j%i, i); gcd2(j%i, i) gcd2 j%i j i i int i i int j j public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    }
    
    System.out.println(sum);
  } main {
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    }
    
    System.out.println(sum);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int sum = 0; sum 0 for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    } {
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    } for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	} int j = i+1; int j = i+1; j i+1 i 1 j <= n j n j++ j++ j {
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	} {
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	} int gcd2tmp = gcd2(i, j); gcd2tmp gcd2(i, j) gcd2 i j for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	} int k = j+1; int k = j+1; k j+1 j 1 k <= n k n k++ k++ k {
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	} {
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	} sum += gcd2(gcd2tmp, k) * 6 sum gcd2(gcd2tmp, k) * 6 gcd2(gcd2tmp, k) gcd2 gcd2tmp k 6 sum += gcd2tmp * 6 sum gcd2tmp * 6 gcd2tmp 6 sum += i sum i System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
  
  public static int gcd2(int i, int j){
    if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    }
  }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    }
    
    System.out.println(sum);
  }
} public class Main {
  
  public static int gcd2(int i, int j){
    if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    }
  }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    }
    
    System.out.println(sum);
  }
} Main
import java.util.*;
public class Main {
  
  public static int gcd2(int i, int j){
    if(i == 0){
      return j;
    }
    else
    {
      return gcd2(j%i, i);
    }
  }
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int sum = 0;
    for(int i = 1; i <= n; i++){
      	for(int j = i+1; j <= n; j++){
          	int gcd2tmp = gcd2(i, j);
          	for(int k = j+1; k <= n; k++){
            	//3 items
      			sum += gcd2(gcd2tmp, k) * 6;
          	}
          	//2 items
          	sum += gcd2tmp * 6;
          	//System.out.println(gcd2tmp);
    	}
      //1 item
      sum += i;
    }
    
    System.out.println(sum);
  }
}