import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        } {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        } for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            } int j=1; int j=1; j 1 j<=n j n j++ j++ j {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            } {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            } for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                } int k=1; int k=1; k 1 k<=n k n k++ k++ k {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                } {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                } int a=i; a i int b=j; b j int c=k; c k int d=0; d 0 while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    } a%b>0 a%b a b 0 {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    } if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        } a<b a b {
                          d=b;
                          b=a;
                          a=d;
                        } d=b d b b=a b a a=d a d {
                            a=a%b;
                        } a=a%b a a%b a b while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    } b%c>0 b%c b c 0 {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    } if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        } b<c b c {
                            d=c;
                            c=b;
                            b=d;
                        } d=c d c c=b c b b=d b d {
                            b=b%c;
                        } b=b%c b b%c b c ans+=c ans c System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                for (int k=1;k<=n;k++) {
                    int a=i;
                    int b=j;
                    int c=k;
                    int d=0;
                    while (a%b>0) {
                        if (a<b) {
                          d=b;
                          b=a;
                          a=d;
                        } else {
                            a=a%b;
                        }
                    }
                    while (b%c>0) {
                        if (b<c) {
                            d=c;
                            c=b;
                            b=d;
                        } else {
                            b=b%c;
                        }
                    }
                    ans+=c;
                }
            }
        }
        System.out.println(ans);
    }
}
