import java.util.Map.Entry;
import java.util.*;

import org.w3c.dom.css.Counter;

public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
}
    public static long  hogehoge(long a , long b){
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    }
}

 import java.util.Map.Entry; Entry java.util.Map import java.util.*; util.* java import org.w3c.dom.css.Counter; Counter org.w3c.dom.css public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
}
    public static long  hogehoge(long a , long b){
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    }
} Main public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
} main {
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
} Scanner s = new Scanner(System.in); s new Scanner(System.in) long n = s.nextInt(); n s.nextInt() s.nextInt s long an = 0; an 0 for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    } long i = 1 ; long i = 1 ; i 1 i<=n i n i++ i++ i {
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    } {
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    } for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        } long i2 =1; long i2 =1; i2 1 i2 <= i i2 i i2++ i2++ i2 {
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        } {
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        } for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            } long i3 =1; long i3 =1; i3 1 i3 <= i2 i3 i2 i3++ i3++ i3 {
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            } {
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            } long huge = hogehoge(i,i2); huge hogehoge(i,i2) hogehoge i i2 huge = hogehoge(huge,i3) huge hogehoge(huge,i3) hogehoge huge i3 if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                } i == i2 && i2==i3 i == i2 i i2 i2==i3 i2 i3 {
                    an += huge;
                } an += huge an huge if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                } i ==i2 || i2 ==i3 i ==i2 i i2 i2 ==i3 i2 i3 {
                    an += huge*3;
                } an += huge*3 an huge*3 huge 3 {
                    an += huge *6;
                } an += huge *6 an huge *6 huge 6 System.out.println(an) System.out.println System.out System System.out an String[] args args public static long  hogehoge(long a , long b){
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    } hogehoge {
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    } long tmp; tmp long x =a; x a long y=b; y b while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        } (tmp = x % y) != 0 (tmp = x % y) tmp x % y x y 0 {
            x = y;
            y = tmp;
        } x = y x y y = tmp y tmp return y; y long a a long b b public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
}
    public static long  hogehoge(long a , long b){
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    }
} public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
}
    public static long  hogehoge(long a , long b){
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    }
} Main
import java.util.Map.Entry;
import java.util.*;

import org.w3c.dom.css.Counter;

public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
}
    public static long  hogehoge(long a , long b){
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    }
}


