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

//Mann Shah [ DAIICT ].
//fast io

public class Main {
	static int mod = (int) (1e9+7);
	static long N = (long)(2*1e5);
	static InputReader in;
    static PrintWriter out;
    static Debugger deb;
    
    public static int lower_bound(int[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        }
    		return first;
    }
    
    public static int gcd(int a, int b){ 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
    } 
    
    public static char chk(char n) {
    		
    		if(n=='1') {
    			return '2';
    		}
    		return '1';
    }
    
	public static void main(String args[] ) throws NumberFormatException, IOException  {
			
		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();
	    
	    int k = in.nextInt();
	    
	    int gcd =0;
	    for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    }
	    
	    out.println(gcd);
	    out.close();
	}
		
/* TC space



 */
		
		static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }
	        
	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    }
		
		static class Debugger{
			public void n(int x) {
				out.println(x);
			}
			
			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		}
		
}


class Pairx {
	Pair a;
	int b;
	public Pairx(Pair a,int b) {
		this.a =a;
		this.b =b;
	}
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pairx)) return false;
	    Pairx p = (Pairx) o;
	    return  b == p.b;
	}
	public int compareTo(Pairx that) {
		return (int)(this.a.x - that.a.x);
	}
}


//Pair arr[] = new Pair[n]; 
//arr[0] = new Pair(10, 20); 
 class Pair { 
    int x; 
    int y; 
  
    // Constructor 
    public Pair(int x, int y) 
    { 
        this.x = x; 
        this.y = y; 
    } 
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pair)) return false;
	    Pair p = (Pair) o;
	    return x == p.x && y == p.y;
	}
} 
// class Compare { 
//	  //void return by default.
//    static Pair[] compare(Pair arr[], int n) 
//    { 
 
 		// (p1,p2) -> p1.x-p2.x Using lembda function...
 
//        // Comparator to sort the pair according to first element.
//        Arrays.sort(arr, new Comparator<Pair>() { 
//            @Override public int compare(Pair p1, Pair p2) 
//            { 
//                return p1.x - p2.x; 
//            } 
//        }); 
//        
//        return arr;
//    } 
//} 




class couple implements Comparable<couple>
{ int x,y;
  public couple(int m,int f) {
 	 x=m;
 	 y=f;
  }
	public int compareTo(couple o) {
		
		 
		return x-o.x;
	}  
} import java.io.*; io.* java import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java import java.math.*; math.* java public class Main {
	static int mod = (int) (1e9+7);
	static long N = (long)(2*1e5);
	static InputReader in;
    static PrintWriter out;
    static Debugger deb;
    
    public static int lower_bound(int[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        }
    		return first;
    }
    
    public static int gcd(int a, int b){ 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
    } 
    
    public static char chk(char n) {
    		
    		if(n=='1') {
    			return '2';
    		}
    		return '1';
    }
    
	public static void main(String args[] ) throws NumberFormatException, IOException  {
			
		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();
	    
	    int k = in.nextInt();
	    
	    int gcd =0;
	    for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    }
	    
	    out.println(gcd);
	    out.close();
	}
		
/* TC space



 */
		
		static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }
	        
	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    }
		
		static class Debugger{
			public void n(int x) {
				out.println(x);
			}
			
			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		}
		
} Main static int mod = (int) (1e9+7); mod (int) (1e9+7) 1e9 7 static long N = (long)(2*1e5); N (long)(2*1e5) 2 1e5 static InputReader in; in static PrintWriter out; out static Debugger deb; deb public static int lower_bound(int[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        }
    		return first;
    } lower_bound { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        }
    		return first;
    } int first = 0 first 0 last = a.length last a.length a a.length mid; mid while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        } first < last first last {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        } mid = first + ((last - first) >> 1) mid first + ((last - first) >> 1) first ((last - first) >> 1) (last - first) last first 1 if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid; a[mid] < k a[mid] a mid k first = mid + 1 first mid + 1 mid 1 last = mid last mid return first; first int[] a a int k k public static int gcd(int a, int b){ 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
    } gcd { 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
    } if (a == 0) 
	        return b; a == 0 a 0 return b; b return gcd(b % a, a); gcd(b % a, a) gcd b % a b a a int a a int b b public static char chk(char n) {
    		
    		if(n=='1') {
    			return '2';
    		}
    		return '1';
    } chk {
    		
    		if(n=='1') {
    			return '2';
    		}
    		return '1';
    } if(n=='1') {
    			return '2';
    		} n=='1' n '1' {
    			return '2';
    		} return '2'; '2' return '1'; '1' char n n public static void main(String args[] ) throws NumberFormatException, IOException  {
			
		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();
	    
	    int k = in.nextInt();
	    
	    int gcd =0;
	    for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    }
	    
	    out.println(gcd);
	    out.close();
	} main {
			
		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();
	    
	    int k = in.nextInt();
	    
	    int gcd =0;
	    for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    }
	    
	    out.println(gcd);
	    out.close();
	} in = new InputReader(System.in) in new InputReader(System.in) out = new PrintWriter(System.out) out new PrintWriter(System.out) deb = new Debugger() deb new Debugger() int k = in.nextInt(); k in.nextInt() in.nextInt in int gcd =0; gcd 0 for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    } {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    } for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		} {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		} for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			} int ll=1; int ll=1; ll 1 ll<=k ll k ll++ ll++ ll {
	    				gcd += gcd(i,gcd(ll,j));
	    			} {
	    				gcd += gcd(i,gcd(ll,j));
	    			} gcd += gcd(i,gcd(ll,j)) gcd gcd(i,gcd(ll,j)) gcd i gcd(ll,j) gcd ll j out.println(gcd) out.println out gcd out.close() out.close out String args[] args static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }
	        
	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    } InputReader private final InputStream stream; stream private final byte[] buf = new byte[8192]; buf new byte[8192] 8192 private int curChar curChar snumChars; snumChars private SpaceCharFilter filter; filter public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        } InputReader {
	                this.stream = stream;
	        } this.stream = stream this.stream this this.stream stream InputStream stream stream public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        } snext {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        } if (snumChars == -1)
	                        throw new InputMismatchException(); snumChars == -1 snumChars -1 1 throw new InputMismatchException(); new InputMismatchException() if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                } curChar >= snumChars curChar snumChars {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                } curChar = 0 curChar 0 try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        } IOException e {
	                                throw new InputMismatchException();
	                        } throw new InputMismatchException(); new InputMismatchException() {
	                                snumChars = stream.read(buf);
	                        } snumChars = stream.read(buf) snumChars stream.read(buf) stream.read stream buf if (snumChars <= 0)
	                                return -1; snumChars <= 0 snumChars 0 return -1; -1 1 return buf[curChar++]; buf[curChar++] buf curChar++ curChar public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        } nextInt {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        } int c = snext(); c snext() snext while (isSpaceChar(c))
	                {
	                        c = snext();
	                } isSpaceChar(c) isSpaceChar c {
	                        c = snext();
	                } c = snext() c snext() snext int sgn = 1; sgn 1 if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                } c == '-' c '-' {
	                        sgn = -1;
	                        c = snext();
	                } sgn = -1 sgn -1 1 c = snext() c snext() snext int res = 0; res 0 do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } if (c < '0' || c > '9')
	                                throw new InputMismatchException(); c < '0' || c > '9' c < '0' c '0' c > '9' c '9' throw new InputMismatchException(); new InputMismatchException() res *= 10 res 10 res += c - '0' res c - '0' c '0' c = snext() c snext() snext return res * sgn; res * sgn res sgn public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        } nextLong {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        } int c = snext(); c snext() snext while (isSpaceChar(c))
	                {
	                        c = snext();
	                } isSpaceChar(c) isSpaceChar c {
	                        c = snext();
	                } c = snext() c snext() snext int sgn = 1; sgn 1 if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                } c == '-' c '-' {
	                        sgn = -1;
	                        c = snext();
	                } sgn = -1 sgn -1 1 c = snext() c snext() snext long res = 0; res 0 do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } if (c < '0' || c > '9')
	                                throw new InputMismatchException(); c < '0' || c > '9' c < '0' c '0' c > '9' c '9' throw new InputMismatchException(); new InputMismatchException() res *= 10 res 10 res += c - '0' res c - '0' c '0' c = snext() c snext() snext return res * sgn; res * sgn res sgn public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        } nextIntArray {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        } int a[] = new int[n]; a new int[n] n for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	                        a[i] = nextInt();
	                } {
	                        a[i] = nextInt();
	                } a[i] = nextInt() a[i] a i nextInt() nextInt return a; a int n n public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        } nextLongArray {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        } long a[] = new long[n]; a new long[n] n for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	                        a[i] = nextLong();
	                } {
	                        a[i] = nextLong();
	                } a[i] = nextLong() a[i] a i nextLong() nextLong return a; a int n n public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        } nextArrayList {
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        } ArrayList<Integer> x = new ArrayList<Integer>(); x new ArrayList<Integer>() for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			} int i=0; int i=0; i 0 i<n i n i++ i++ i {
	        				int v = in.nextInt();
	        				x.add(v);
	        			} {
	        				int v = in.nextInt();
	        				x.add(v);
	        			} int v = in.nextInt(); v in.nextInt() in.nextInt in x.add(v) x.add x v return x; x int n n public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        } readString {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        } int c = snext(); c snext() snext while (isSpaceChar(c))
	                {
	                        c = snext();
	                } isSpaceChar(c) isSpaceChar c {
	                        c = snext();
	                } c = snext() c snext() snext StringBuilder res = new StringBuilder(); res new StringBuilder() do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } res.appendCodePoint(c) res.appendCodePoint res c c = snext() c snext() snext return res.toString(); res.toString() res.toString res public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        } nextLine {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        } int c = snext(); c snext() snext while (isSpaceChar(c))
	                        c = snext(); isSpaceChar(c) isSpaceChar c c = snext() c snext() snext StringBuilder res = new StringBuilder(); res new StringBuilder() do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c)); !isEndOfLine(c) isEndOfLine(c) isEndOfLine c {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } res.appendCodePoint(c) res.appendCodePoint res c c = snext() c snext() snext return res.toString(); res.toString() res.toString res public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        } isSpaceChar {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        } if (filter != null)
	                        return filter.isSpaceChar(c); filter != null filter null return filter.isSpaceChar(c); filter.isSpaceChar(c) filter.isSpaceChar filter c return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == '\t' c == '\r' c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == ' ' c ' ' c == '\n' c '\n' c == '\r' c '\r' c == '\t' c '\t' c == -1 c -1 1 int c c private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        } isEndOfLine {
	                return c == '\n' || c == '\r' || c == -1;
	        } return c == '\n' || c == '\r' || c == -1; c == '\n' || c == '\r' || c == -1 c == '\n' || c == '\r' || c == -1 c == '\n' c '\n' c == '\r' c '\r' c == -1 c -1 1 int c c public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        } SpaceCharFilter public boolean isSpaceChar(int ch); isSpaceChar int ch ch static class Debugger{
			public void n(int x) {
				out.println(x);
			}
			
			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		} Debugger public void n(int x) {
				out.println(x);
			} n {
				out.println(x);
			} out.println(x) out.println out x int x x public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			} a {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			} StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        } int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
		        		sb.append(a[i]+" ");
		        } {
		        		sb.append(a[i]+" ");
		        } sb.append(a[i]+" ") sb.append sb a[i]+" " a[i] a i " " out.println(sb.toString()) out.println out sb.toString() sb.toString sb int[] a a class Pairx {
	Pair a;
	int b;
	public Pairx(Pair a,int b) {
		this.a =a;
		this.b =b;
	}
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pairx)) return false;
	    Pairx p = (Pairx) o;
	    return  b == p.b;
	}
	public int compareTo(Pairx that) {
		return (int)(this.a.x - that.a.x);
	}
} Pairx Pair a; a int b; b public Pairx(Pair a,int b) {
		this.a =a;
		this.b =b;
	} Pairx {
		this.a =a;
		this.b =b;
	} this.a =a this.a this this.a a this.b =b this.b this this.b b Pair a a int b b @Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pairx)) return false;
	    Pairx p = (Pairx) o;
	    return  b == p.b;
	} equals {
	    if (this == o) return true;
	    if (!(o instanceof Pairx)) return false;
	    Pairx p = (Pairx) o;
	    return  b == p.b;
	} if (this == o) return true; this == o this o return true; true if (!(o instanceof Pairx)) return false; !(o instanceof Pairx) (o instanceof Pairx) o Pairx return false; false Pairx p = (Pairx) o; p (Pairx) o return  b == p.b; b == p.b b p.b p p.b Object o o public int compareTo(Pairx that) {
		return (int)(this.a.x - that.a.x);
	} compareTo {
		return (int)(this.a.x - that.a.x);
	} return (int)(this.a.x - that.a.x); (int)(this.a.x - that.a.x) this.a.x this.a this this.a this.a.x that.a.x that.a that that.a that.a.x Pairx that that  class Pair { 
    int x; 
    int y; 
  
    // Constructor 
    public Pair(int x, int y) 
    { 
        this.x = x; 
        this.y = y; 
    } 
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pair)) return false;
	    Pair p = (Pair) o;
	    return x == p.x && y == p.y;
	}
} Pair int x; x int y; y // Constructor 
    public Pair(int x, int y) 
    { 
        this.x = x; 
        this.y = y; 
    } Pair { 
        this.x = x; 
        this.y = y; 
    } this.x = x this.x this this.x x this.y = y this.y this this.y y int x x int y y @Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pair)) return false;
	    Pair p = (Pair) o;
	    return x == p.x && y == p.y;
	} equals {
	    if (this == o) return true;
	    if (!(o instanceof Pair)) return false;
	    Pair p = (Pair) o;
	    return x == p.x && y == p.y;
	} if (this == o) return true; this == o this o return true; true if (!(o instanceof Pair)) return false; !(o instanceof Pair) (o instanceof Pair) o Pair return false; false Pair p = (Pair) o; p (Pair) o return x == p.x && y == p.y; x == p.x && y == p.y x == p.x x p.x p p.x y == p.y y p.y p p.y Object o o class couple implements Comparable<couple>
{ int x,y;
  public couple(int m,int f) {
 	 x=m;
 	 y=f;
  }
	public int compareTo(couple o) {
		
		 
		return x-o.x;
	}  
} couple int x x y; y public couple(int m,int f) {
 	 x=m;
 	 y=f;
  } couple {
 	 x=m;
 	 y=f;
  } x=m x m y=f y f int m m int f f public int compareTo(couple o) {
		
		 
		return x-o.x;
	} compareTo {
		
		 
		return x-o.x;
	} return x-o.x; x-o.x x o.x o o.x couple o o Comparable public class Main {
	static int mod = (int) (1e9+7);
	static long N = (long)(2*1e5);
	static InputReader in;
    static PrintWriter out;
    static Debugger deb;
    
    public static int lower_bound(int[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        }
    		return first;
    }
    
    public static int gcd(int a, int b){ 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
    } 
    
    public static char chk(char n) {
    		
    		if(n=='1') {
    			return '2';
    		}
    		return '1';
    }
    
	public static void main(String args[] ) throws NumberFormatException, IOException  {
			
		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();
	    
	    int k = in.nextInt();
	    
	    int gcd =0;
	    for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    }
	    
	    out.println(gcd);
	    out.close();
	}
		
/* TC space



 */
		
		static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }
	        
	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    }
		
		static class Debugger{
			public void n(int x) {
				out.println(x);
			}
			
			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		}
		
} public class Main {
	static int mod = (int) (1e9+7);
	static long N = (long)(2*1e5);
	static InputReader in;
    static PrintWriter out;
    static Debugger deb;
    
    public static int lower_bound(int[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        }
    		return first;
    }
    
    public static int gcd(int a, int b){ 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
    } 
    
    public static char chk(char n) {
    		
    		if(n=='1') {
    			return '2';
    		}
    		return '1';
    }
    
	public static void main(String args[] ) throws NumberFormatException, IOException  {
			
		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();
	    
	    int k = in.nextInt();
	    
	    int gcd =0;
	    for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    }
	    
	    out.println(gcd);
	    out.close();
	}
		
/* TC space



 */
		
		static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }
	        
	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    }
		
		static class Debugger{
			public void n(int x) {
				out.println(x);
			}
			
			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		}
		
} Main
import java.io.*;
import java.math.BigInteger; 
import java.util.*;
import java.math.*; 

//Mann Shah [ DAIICT ].
//fast io

public class Main {
	static int mod = (int) (1e9+7);
	static long N = (long)(2*1e5);
	static InputReader in;
    static PrintWriter out;
    static Debugger deb;
    
    public static int lower_bound(int[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1); 
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1; 
            else 
                last = mid;
        }
    		return first;
    }
    
    public static int gcd(int a, int b){ 
	    if (a == 0) 
	        return b;  
	    return gcd(b % a, a);  
    } 
    
    public static char chk(char n) {
    		
    		if(n=='1') {
    			return '2';
    		}
    		return '1';
    }
    
	public static void main(String args[] ) throws NumberFormatException, IOException  {
			
		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();
	    
	    int k = in.nextInt();
	    
	    int gcd =0;
	    for(int i=1;i<=k;i++) {
	    		for(int j=1;j<=k;j++) {
	    			for(int ll=1;ll<=k;ll++) {
	    				gcd += gcd(i,gcd(ll,j));
	    			}
	    		}
	    }
	    
	    out.println(gcd);
	    out.close();
	}
		
/* TC space



 */
		
		static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }
	        
	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    }
		
		static class Debugger{
			public void n(int x) {
				out.println(x);
			}
			
			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		}
		
}


class Pairx {
	Pair a;
	int b;
	public Pairx(Pair a,int b) {
		this.a =a;
		this.b =b;
	}
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pairx)) return false;
	    Pairx p = (Pairx) o;
	    return  b == p.b;
	}
	public int compareTo(Pairx that) {
		return (int)(this.a.x - that.a.x);
	}
}


//Pair arr[] = new Pair[n]; 
//arr[0] = new Pair(10, 20); 
 class Pair { 
    int x; 
    int y; 
  
    // Constructor 
    public Pair(int x, int y) 
    { 
        this.x = x; 
        this.y = y; 
    } 
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pair)) return false;
	    Pair p = (Pair) o;
	    return x == p.x && y == p.y;
	}
} 
// class Compare { 
//	  //void return by default.
//    static Pair[] compare(Pair arr[], int n) 
//    { 
 
 		// (p1,p2) -> p1.x-p2.x Using lembda function...
 
//        // Comparator to sort the pair according to first element.
//        Arrays.sort(arr, new Comparator<Pair>() { 
//            @Override public int compare(Pair p1, Pair p2) 
//            { 
//                return p1.x - p2.x; 
//            } 
//        }); 
//        
//        return arr;
//    } 
//} 




class couple implements Comparable<couple>
{ int x,y;
  public couple(int m,int f) {
 	 x=m;
 	 y=f;
  }
	public int compareTo(couple o) {
		
		 
		return x-o.x;
	}  
}
