import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k,n,m = 0,sum = 0;

        k = sc.nextInt();
        
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        }
        
        System.out.println(sum);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k,n,m = 0,sum = 0;

        k = sc.nextInt();
        
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        }
        
        System.out.println(sum);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k,n,m = 0,sum = 0;

        k = sc.nextInt();
        
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        }
        
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        int k,n,m = 0,sum = 0;

        k = sc.nextInt();
        
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        }
        
        System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k k n n m = 0 m 0 sum = 0; sum 0 k = sc.nextInt() k sc.nextInt() sc.nextInt sc for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        } int a = 1; int a = 1; a 1 a <= k a k a++ a++ a {
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        } {
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        } for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            } int b = 1; int b = 1; b 1 b <= k b k b++ b++ b {
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            } {
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            } for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                } int c = 1; int c = 1; c 1 c <= k c k c++ c++ c {
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                } {
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                } int x x y y z z tmp; tmp x = a x a y = b y b z = c z c if(a < b){
                        x = b;
                        y = a;
                    } a < b a b {
                        x = b;
                        y = a;
                    } x = b x b y = a y a 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 while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    } (tmp = y % z) != 0 (tmp = y % z) tmp y % z y z 0 {
                        y = z;
                        z = tmp;
                    } y = z y z z = tmp z tmp sum += z sum z 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) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k,n,m = 0,sum = 0;

        k = sc.nextInt();
        
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        }
        
        System.out.println(sum);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k,n,m = 0,sum = 0;

        k = sc.nextInt();
        
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        }
        
        System.out.println(sum);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k,n,m = 0,sum = 0;

        k = sc.nextInt();
        
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    
                    int x,y,z,tmp;
                    x = a;
                    y = b;
                    z = c;
                    
                    if(a < b){
                        x = b;
                        y = a;
                    }
                    
                    
                    while ((tmp = x % y) != 0) {
                        x = y;
                        y = tmp;
                    }
                    
                    while ((tmp = y % z) != 0) {
                        y = z;
                        z = tmp;
                    }
                    
                    sum += z;

                }
            }
            
        }
        
        System.out.println(sum);
    }
}
