import java.util.*;
public class Main{
    
    public static int gcd(int a, int b){
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    }
    
     public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     }
} import java.util.*; util.* java public class Main{
    
    public static int gcd(int a, int b){
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    }
    
     public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     }
} Main public static int gcd(int a, int b){
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    } gcd {
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    } if ( a == 0 ) return b; a == 0 a 0 return b; b return gcd(b%a, a); gcd(b%a, a) gcd b%a b a a int a a int b b public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     } main {
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int a = scan.nextInt(); a scan.nextInt() scan.nextInt scan long s = 0; s 0 for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         } int i=1; int i=1; i 1 i<=a i a i++ i++ i {
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         } {
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         } for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             } int j=1; int j=1; j 1 j<=a j a j++ j++ j {
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             } {
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             } for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 } int k=1; int k=1; k 1 k<=a k a k++ k++ k {
                     s+=gcd(gcd(i,j), k);
                 } {
                     s+=gcd(gcd(i,j), k);
                 } s+=gcd(gcd(i,j), k) s gcd(gcd(i,j), k) gcd gcd(i,j) gcd i j k System.out.println(s) System.out.println System.out System System.out s String []args args public class Main{
    
    public static int gcd(int a, int b){
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    }
    
     public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     }
} public class Main{
    
    public static int gcd(int a, int b){
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    }
    
     public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     }
} Main
import java.util.*;
public class Main{
    
    public static int gcd(int a, int b){
        if ( a == 0 ) return b;
        
        return gcd(b%a, a);
    }
    
     public static void main(String []args){
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         
         long s = 0;
         for (int i=1;i<=a;i++){
             for (int j=1;j<=a;j++){
                 for (int k=1;k<=a;k++){
                     s+=gcd(gcd(i,j), k);
                 }
             }
         }
         
         System.out.println(s);
     }
}