import java.math.BigInteger;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        }
        System.out.println(sum);
    }
} import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        }
        System.out.println(sum);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        }
        System.out.println(sum);
    } main {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        }
        System.out.println(sum);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int K = in.nextInt(); K in.nextInt() in.nextInt in int sum = 0; sum 0 for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        } int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        } {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        } for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            } int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            } {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            } for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                } int k = 1; int k = 1; k 1 k <= K k K k++ k++ k {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                } {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                } sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue() sum BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue() BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)) BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)) BigInteger.valueOf(i).gcd BigInteger.valueOf(i) BigInteger.valueOf BigInteger i BigInteger.valueOf(j) BigInteger.valueOf BigInteger j BigInteger.valueOf(k) BigInteger.valueOf BigInteger k System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        }
        System.out.println(sum);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        }
        System.out.println(sum);
    }
} Main
import java.math.BigInteger;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int sum = 0;
        for (int i = 1; i <= K; i++) {
            for (int j = 1; j <= K; j++) {
                for (int k = 1; k <= K; k++) {
                    sum += BigInteger.valueOf(i).gcd(BigInteger.valueOf(j)).gcd(BigInteger.valueOf(k)).intValue();
                }
            }
        }
        System.out.println(sum);
    }
}