import java.util.*;

class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int x = sc.nextInt();
   int y = 0;
   Gcd gcd = new Gcd();
   for(int i=1;i<=x;i++){
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   }
   System.out.println(y);
 }
}

class Gcd{
   int gcd(int a,int b,int c){
     int min = a;
     int num = 1;
     if(a>b&&b<=c)
       min = b;
     else if(a>b&&b>c)
       min = c;
     
     for(int i=1;i<=min;i++){
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     }
     return num;
   }
} import java.util.*; util.* java class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int x = sc.nextInt();
   int y = 0;
   Gcd gcd = new Gcd();
   for(int i=1;i<=x;i++){
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   }
   System.out.println(y);
 }
} Main public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int x = sc.nextInt();
   int y = 0;
   Gcd gcd = new Gcd();
   for(int i=1;i<=x;i++){
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   }
   System.out.println(y);
 } main {
   Scanner sc = new Scanner(System.in);
   int x = sc.nextInt();
   int y = 0;
   Gcd gcd = new Gcd();
   for(int i=1;i<=x;i++){
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   }
   System.out.println(y);
 } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int y = 0; y 0 Gcd gcd = new Gcd(); gcd new Gcd() for(int i=1;i<=x;i++){
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   } int i=1; int i=1; i 1 i<=x i x i++ i++ i {
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   } {
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   } for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     } int j=1; int j=1; j 1 j<=x j x j++ j++ j {
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     } {
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     } for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k); int k=1; int k=1; k 1 k<=x k x k++ k++ k y+=gcd.gcd(i,j,k); y+=gcd.gcd(i,j,k) y gcd.gcd(i,j,k) gcd.gcd gcd i j k System.out.println(y) System.out.println System.out System System.out y String args[] args class Gcd{
   int gcd(int a,int b,int c){
     int min = a;
     int num = 1;
     if(a>b&&b<=c)
       min = b;
     else if(a>b&&b>c)
       min = c;
     
     for(int i=1;i<=min;i++){
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     }
     return num;
   }
} Gcd int gcd(int a,int b,int c){
     int min = a;
     int num = 1;
     if(a>b&&b<=c)
       min = b;
     else if(a>b&&b>c)
       min = c;
     
     for(int i=1;i<=min;i++){
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     }
     return num;
   } gcd {
     int min = a;
     int num = 1;
     if(a>b&&b<=c)
       min = b;
     else if(a>b&&b>c)
       min = c;
     
     for(int i=1;i<=min;i++){
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     }
     return num;
   } int min = a; min a int num = 1; num 1 if(a>b&&b<=c)
       min = b;
     else if(a>b&&b>c)
       min = c; a>b&&b<=c a>b a b b<=c b c min = b min b if(a>b&&b>c)
       min = c; a>b&&b>c a>b a b b>c b c min = c min c for(int i=1;i<=min;i++){
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     } int i=1; int i=1; i 1 i<=min i min i++ i++ i {
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     } {
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     } if(a%i==0&&b%i==0&&c%i==0)
         num = i; a%i==0&&b%i==0&&c%i==0 a%i==0&&b%i==0&&c%i==0 a%i==0 a%i a i 0 b%i==0 b%i b i 0 c%i==0 c%i c i 0 num = i num i return num; num int a a int b b int c c
import java.util.*;

class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int x = sc.nextInt();
   int y = 0;
   Gcd gcd = new Gcd();
   for(int i=1;i<=x;i++){
     for(int j=1;j<=x;j++){
       for(int k=1;k<=x;k++)
         y+=gcd.gcd(i,j,k);
     }
   }
   System.out.println(y);
 }
}

class Gcd{
   int gcd(int a,int b,int c){
     int min = a;
     int num = 1;
     if(a>b&&b<=c)
       min = b;
     else if(a>b&&b>c)
       min = c;
     
     for(int i=1;i<=min;i++){
       if(a%i==0&&b%i==0&&c%i==0)
         num = i;
     }
     return num;
   }
}