import java.util.*;
public class Main{
	static int gcd(int p,int q){
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  }
} import java.util.*; util.* java public class Main{
	static int gcd(int p,int q){
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  }
} Main static int gcd(int p,int q){
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	} gcd {
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	} while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		} (p%q)!=0 (p%q) p q 0 {
			int r=p%q;
			p=q;
			q=r;
		} int r=p%q; r p%q p q p=q p q q=r q r return q; q int p p int q q public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  } main {
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k=sc.nextInt(); k sc.nextInt() sc.nextInt sc int sum=0; sum 0 for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	} 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 d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	} {
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	} for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		} int b=1; int b=1; b 1 b<=k b k b++ b++ b {
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		} {
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		} for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			} int c=1; int c=1; c 1 c<=k c k c++ c++ c {
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			} {
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			} int d= gcd(c,gcd(b,a)); d gcd(c,gcd(b,a)) gcd c gcd(b,a) gcd b a sum +=d sum d System.out.print(sum) System.out.print System.out System System.out sum String[] args args public class Main{
	static int gcd(int p,int q){
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  }
} public class Main{
	static int gcd(int p,int q){
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  }
} Main
import java.util.*;
public class Main{
	static int gcd(int p,int q){
		while((p%q)!=0){
			int r=p%q;
			p=q;
			q=r;
		}
		return q;
	}
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int k=sc.nextInt();
  	int sum=0;
  	for(int a=1;a<=k;a++){
  		for(int b=1;b<=k;b++){
  			for(int c=1;c<=k;c++){
  				
  				
  				int d= gcd(c,gcd(b,a));
  					sum +=d;
  			}
  		}
  	}
  	System.out.print(sum);
  }
}