
import java.math.*;
import java.io.*;
import java.util.*;

public class Main {
public static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
public static void main(String[] args) throws Exception{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int count = 0;
      	for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	}
      	System.out.println(count);
    }

}

 import java.math.*; math.* java import java.io.*; io.* java import java.util.*; util.* java public class Main {
public static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
public static void main(String[] args) throws Exception{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int count = 0;
      	for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	}
      	System.out.println(count);
    }

} Main public static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } gcd { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 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) throws Exception{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int count = 0;
      	for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	}
      	System.out.println(count);
    } main {

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int count = 0;
      	for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	}
      	System.out.println(count);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int count = 0; count 0 for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	} {
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	} for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		} int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		} {
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		} for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			} int k = 1; int k = 1; k 1 k <= n k n k++ k++ k {
      				count += gcd(gcd(i,j),k);
      			} {
      				count += gcd(gcd(i,j),k);
      			} count += gcd(gcd(i,j),k) count gcd(gcd(i,j),k) gcd gcd(i,j) gcd i j k System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
public static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
public static void main(String[] args) throws Exception{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int count = 0;
      	for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	}
      	System.out.println(count);
    }

} public class Main {
public static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
public static void main(String[] args) throws Exception{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int count = 0;
      	for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	}
      	System.out.println(count);
    }

} Main

import java.math.*;
import java.io.*;
import java.util.*;

public class Main {
public static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
public static void main(String[] args) throws Exception{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int n = Integer.parseInt(br.readLine());
      	int count = 0;
      	for(int i = 1; i <= n; i++)
      	{
      		for(int j = 1; j <= n; j++)
      		{
      			for(int k = 1; k <= n; k++)
      			{
      				count += gcd(gcd(i,j),k);
      			}
      		}
      	}
      	System.out.println(count);
    }

}


