/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    
    public static int printgcd(int i,int j,int k){
        BigInteger b1,b2,b3,b4;
        b1 = BigInteger.valueOf(i);
        b2 = BigInteger.valueOf(j);
        b3 = BigInteger.valueOf(k);
        b4=b1.gcd(b2);
        b4=b4.gcd(b3);
        return b4.intValue();
        
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	   long sum = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		}
		System.out.println(sum);
		
		
	}
	
	
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java import java.math.*; math.* java public class Main
{
    
    public static int printgcd(int i,int j,int k){
        BigInteger b1,b2,b3,b4;
        b1 = BigInteger.valueOf(i);
        b2 = BigInteger.valueOf(j);
        b3 = BigInteger.valueOf(k);
        b4=b1.gcd(b2);
        b4=b4.gcd(b3);
        return b4.intValue();
        
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	   long sum = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		}
		System.out.println(sum);
		
		
	}
	
	
} Main public static int printgcd(int i,int j,int k){
        BigInteger b1,b2,b3,b4;
        b1 = BigInteger.valueOf(i);
        b2 = BigInteger.valueOf(j);
        b3 = BigInteger.valueOf(k);
        b4=b1.gcd(b2);
        b4=b4.gcd(b3);
        return b4.intValue();
        
    } printgcd {
        BigInteger b1,b2,b3,b4;
        b1 = BigInteger.valueOf(i);
        b2 = BigInteger.valueOf(j);
        b3 = BigInteger.valueOf(k);
        b4=b1.gcd(b2);
        b4=b4.gcd(b3);
        return b4.intValue();
        
    } BigInteger b1 b1 b2 b2 b3 b3 b4; b4 b1 = BigInteger.valueOf(i) b1 BigInteger.valueOf(i) BigInteger.valueOf BigInteger i b2 = BigInteger.valueOf(j) b2 BigInteger.valueOf(j) BigInteger.valueOf BigInteger j b3 = BigInteger.valueOf(k) b3 BigInteger.valueOf(k) BigInteger.valueOf BigInteger k b4=b1.gcd(b2) b4 b1.gcd(b2) b1.gcd b1 b2 b4=b4.gcd(b3) b4 b4.gcd(b3) b4.gcd b4 b3 return b4.intValue(); b4.intValue() b4.intValue b4 int i i int j j int k k public static void main (String[] args) throws java.lang.Exception
	{
	   long sum = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		}
		System.out.println(sum);
		
		
	} main {
	   long sum = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		}
		System.out.println(sum);
		
		
	} long sum = 0; sum 0 Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		} {
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		} for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	} int j=1; int j=1; j 1 j<=n j n j++ j++ j {
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	} {
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	} for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	} int k=1; int k=1; k 1 k<=n k n k++ k++ k {
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	} {
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	} sum+=Long.valueOf(printgcd(i,j,k)) sum Long.valueOf(printgcd(i,j,k)) Long.valueOf Long printgcd(i,j,k) printgcd i j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main
{
    
    public static int printgcd(int i,int j,int k){
        BigInteger b1,b2,b3,b4;
        b1 = BigInteger.valueOf(i);
        b2 = BigInteger.valueOf(j);
        b3 = BigInteger.valueOf(k);
        b4=b1.gcd(b2);
        b4=b4.gcd(b3);
        return b4.intValue();
        
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	   long sum = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		}
		System.out.println(sum);
		
		
	}
	
	
} public class Main
{
    
    public static int printgcd(int i,int j,int k){
        BigInteger b1,b2,b3,b4;
        b1 = BigInteger.valueOf(i);
        b2 = BigInteger.valueOf(j);
        b3 = BigInteger.valueOf(k);
        b4=b1.gcd(b2);
        b4=b4.gcd(b3);
        return b4.intValue();
        
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	   long sum = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		}
		System.out.println(sum);
		
		
	}
	
	
} Main
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    
    public static int printgcd(int i,int j,int k){
        BigInteger b1,b2,b3,b4;
        b1 = BigInteger.valueOf(i);
        b2 = BigInteger.valueOf(j);
        b3 = BigInteger.valueOf(k);
        b4=b1.gcd(b2);
        b4=b4.gcd(b3);
        return b4.intValue();
        
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	   long sum = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		for(int i=1;i<=n;i++){
		    	for(int j=1;j<=n;j++){
		    	    	for(int k=1;k<=n;k++){
		    	    	   sum+=Long.valueOf(printgcd(i,j,k)); 
		    	    	}
		    	}
		}
		System.out.println(sum);
		
		
	}
	
	
}
