import java.io.*;
import java.util.*;

public class Main {
    static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }
    public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
        
        long kP = k;
        long ans = (kP*(kP+1))/2;

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        }

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        }
        out.println(ans);
        


        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }
    public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
        
        long kP = k;
        long ans = (kP*(kP+1))/2;

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        }

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        }
        out.println(ans);
        


        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
} Main //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out; out static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    } gcd {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    } if (a == 0)
            return b; a == 0 a 0 return b; b if (b == 0)
            return a; b == 0 b 0 return a; a if (a == b)
            return a; a == b a b return a; a if (a > b)
            return gcd(a-b, b); a > b a b return gcd(a-b, b); gcd(a-b, b) gcd a-b a b b return gcd(a, b-a); gcd(a, b-a) gcd a b-a b a int a a int b b public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
        
        long kP = k;
        long ans = (kP*(kP+1))/2;

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        }

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        }
        out.println(ans);
        


        out.close();
    } main {

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
        
        long kP = k;
        long ans = (kP*(kP+1))/2;

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        }

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        }
        out.println(ans);
        


        out.close();
    } FastReader fs = new FastReader(); fs new FastReader() out = new PrintWriter(new BufferedOutputStream(System.out)) out new PrintWriter(new BufferedOutputStream(System.out)) int k = fs.nextInt(); k fs.nextInt() fs.nextInt fs long kP = k; kP k long ans = (kP*(kP+1))/2; ans (kP*(kP+1))/2 (kP*(kP+1)) kP (kP+1) kP 1 2 for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        } int i=1 ; int i=1 ; i 1 i<=k i k i++ i++ i {
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        } {
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        } for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            } int j=i+1 ; int j=i+1 ; j i+1 i 1 j<=k j k j++ j++ j {
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            } {
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            } long calc = (long) gcd(i,j)*6; calc (long) gcd(i,j)*6 (long) gcd(i,j) gcd i j 6 ans += calc ans calc for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        } int i=1 ; int i=1 ; i 1 i<=k i k i++ i++ i {
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        } {
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        } for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            } int j=i+1 ; int j=i+1 ; j i+1 i 1 j<=k j k j++ j++ j {
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            } {
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            } for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                } int l=j+1 ; int l=j+1 ; l j+1 j 1 l<=k l k l++ l++ l {
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                } {
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                } int calc = gcd(i,j); calc gcd(i,j) gcd i j long calcF = gcd(calc,l); calcF gcd(calc,l) gcd calc l ans += calcF*6 ans calcF*6 calcF 6 out.println(ans) out.println out ans out.close() out.close out String[] args args public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        } FastReader {
            br = new BufferedReader(new InputStreamReader(System.in));
        } br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } next {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    st = new StringTokenizer(br.readLine());
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next double nextDouble() {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        } nextLine {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        } String str = ""; str "" try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } IOException e {
                e.printStackTrace();
            } e.printStackTrace() e.printStackTrace e {
                str = br.readLine();
            } str = br.readLine() str br.readLine() br.readLine br return str; str public class Main {
    static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }
    public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
        
        long kP = k;
        long ans = (kP*(kP+1))/2;

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        }

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        }
        out.println(ans);
        


        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
} public class Main {
    static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }
    public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
        
        long kP = k;
        long ans = (kP*(kP+1))/2;

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        }

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        }
        out.println(ans);
        


        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
} Main
import java.io.*;
import java.util.*;

public class Main {
    static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }
    public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
        
        long kP = k;
        long ans = (kP*(kP+1))/2;

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                long calc = (long) gcd(i,j)*6;
                ans += calc;
            }
        }

        for(int i=1 ; i<=k ; i++){
            for(int j=i+1 ; j<=k ; j++){
                for(int l=j+1 ; l<=k ; l++){
                    int calc = gcd(i,j);
                    long calcF = gcd(calc,l);
                    ans += calcF*6;
                }
            }
        }
        out.println(ans);
        


        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}
