
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static int gcd(int a, int b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java import java.lang.*; lang.* java import java.util.stream.*; stream.* java.util public class Main {
    public static int gcd(int a, int b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    }
} Main public static int gcd(int a, int b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    } gcd {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    } if(a < b) return gcd(b,a); a < b a b return gcd(b,a); gcd(b,a) gcd b a if(b == 0) return a; b == 0 b 0 return a; a return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b int a a int b b public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    } main {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Integer k = Integer.parseInt(scanner.next()); k Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int ans = 0; ans 0 for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        } int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        } {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        } for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            } int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            } {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            } for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                } int m = 1; int m = 1; m 1 m <= k m k m++ m++ m {
                    ans += gcd(i, gcd(j,m));
                } {
                    ans += gcd(i, gcd(j,m));
                } ans += gcd(i, gcd(j,m)) ans gcd(i, gcd(j,m)) gcd i gcd(j,m) gcd j m System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static int gcd(int a, int b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static int gcd(int a, int b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    }
} Main

import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static int gcd(int a, int b) {
        if(a < b) return gcd(b,a);
        if(b == 0) return a;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int m = 1; m <= k; m++) {
                    ans += gcd(i, gcd(j,m));
                }
            }
        }
        System.out.println(ans);
    }
}
