import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        }
        private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        }
        private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        }

        static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} import java.io.*; io.* java import java.util.HashSet; HashSet java.util import java.util.Set; Set java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        }
        private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        }
        private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        }

        static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} Main public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) Task solver = new Task(); solver new Task() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        }
        private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        }
        private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        }

        static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        }
    } Task public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        } solve {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        } int k = in.nextInt(); k in.nextInt() in.nextInt in long ans = 0; ans 0 for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            } int i = 1; int i = 1; i 1 i <=k i k i++ i++ i {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            } {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            } for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                } int j = 1; int j = 1; j 1 j <= i j i j++ j++ j {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                } {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                } for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    } int l = j; int l = j; l j l <= i l i l++ l++ l {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    } {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    } long g = gcdMultiple(i,j,l); g gcdMultiple(i,j,l) gcdMultiple i j l if (findUnique(i,j,l) == 1) {
                            ans += g;
                        } findUnique(i,j,l) == 1 findUnique(i,j,l) findUnique i j l 1 {
                            ans += g;
                        } ans += g ans g if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        } findUnique(i,j,l) == 2 findUnique(i,j,l) findUnique i j l 2 {
                            ans += g*3;
                        } ans += g*3 ans g*3 g 3 if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        } findUnique(i,j,l) == 3 findUnique(i,j,l) findUnique i j l 3 {
                            ans += g*6;
                        } ans += g*6 ans g*6 g 6 out.println(ans) out.println out ans int testNumber testNumber InputReader in in PrintWriter out out private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        } findUnique {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        } Set<Integer> set = new HashSet<>(); set new HashSet<>() set.add(a) set.add set a set.add(b) set.add set b set.add(c) set.add set c return set.size(); set.size() set.size set int a a int b b int c c private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        } gcd {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        } if (b == 0){
                return a;
            } b == 0 b 0 {
                return a;
            } return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b int a a int b b static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        } gcdMultiple {
            return gcd(gcd(a,b), c);
        } return gcd(gcd(a,b), c); gcd(gcd(a,b), c) gcd gcd(a,b) gcd a b c int a a int b b int c c static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    } InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } InputReader {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } next {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public double nextDouble() {
            return Double.parseDouble(next());
        } nextDouble {
            return Double.parseDouble(next());
        } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public char nextChar() {
            return next().charAt(0);
        } nextChar {
            return next().charAt(0);
        } return next().charAt(0); next().charAt(0) next().charAt next() next 0 public String nextLine() throws IOException {
            return reader.readLine().trim();
        } nextLine {
            return reader.readLine().trim();
        } return reader.readLine().trim(); reader.readLine().trim() reader.readLine().trim reader.readLine() reader.readLine reader public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        }
        private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        }
        private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        }

        static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        }
        private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        }
        private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        }

        static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
} Main
import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int k = in.nextInt();
            long ans = 0;
            for (int i = 1; i <=k; i++) {
                for (int j = 1; j <= i; j++) {
                    for (int l = j; l <= i ; l++) {
                        long g = gcdMultiple(i,j,l);
                        if (findUnique(i,j,l) == 1) {
                            ans += g;
                        }
                        if (findUnique(i,j,l) == 2) {
                            ans += g*3;
                        }
                        if (findUnique(i,j,l) == 3) {
                            ans += g*6;
                        }
                    }
                }
            }
            out.println(ans);
        }
        private static int findUnique(int a, int b, int c) {
            Set<Integer> set = new HashSet<>();
            set.add(a);
            set.add(b);
            set.add(c);
            return set.size();
        }
        private static int gcd(int a, int b) {
            if (b == 0){
                return a;
            }
            return gcd(b, a % b);
        }

        static int gcdMultiple(int a, int b, int c) {
            return gcd(gcd(a,b), c);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}
