
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum =0;
		int gcdWork=0;
		int gcd =0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		}
		System.out.println(sum);
	}

}


class Gcd {
	int targetA;
	int targetB;
	static int[] targetArray;
	
	public Gcd(int targetNumberA ,int targetNumberB) {
		this.targetA=targetNumberA;
		this.targetB=targetNumberB;
		this.targetArray = new int[2];
		targetArray[0] =targetA;
		targetArray[1] =targetB;
	}
	
	////最大公約数ユークリッドの互除法(int[A,B] )(return int)
	public static int gcdCalc(){
         int x;
         int y;
        if (targetArray[0] > targetArray[1]) {
            x = targetArray[0];
            y = targetArray[1];
        } else {
            x = targetArray[1];
            y = targetArray[0];
        }
        // ここからがユークリッドの互除法を用いた最大公約数を
        // 求める為の式
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return(y);
    }
	
//////最小公倍数(int[A,B] int )(return int)
	////gcdをgcdCalcで求めて代入
	public static int lcmCalc(int gcd) {
        int x;
        int y;
       if (targetArray[0] > targetArray[1]) {
           x = targetArray[0];
           y = targetArray[1];
       } else {
           x = targetArray[1];
           y = targetArray[0];
       }
       int lcm = (x*y)/gcd;
       return(lcm);
	}
	

}

 import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum =0;
		int gcdWork=0;
		int gcd =0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		}
		System.out.println(sum);
	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum =0;
		int gcdWork=0;
		int gcd =0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		}
		System.out.println(sum);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum =0;
		int gcdWork=0;
		int gcd =0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		}
		System.out.println(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 int gcdWork=0; gcdWork 0 int gcd =0; gcd 0 for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		} int i=1; int i=1; i 1 i<=k i k i++ i++ i {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		} {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		} for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			} {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			} for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				} int m=1; int m=1; m 1 m<=k m k m++ m++ m {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				} {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				} Gcd g1 = new Gcd(i,j); g1 new Gcd(i,j) gcdWork=g1.gcdCalc() gcdWork g1.gcdCalc() g1.gcdCalc g1 Gcd g2 = new Gcd(gcdWork,m); g2 new Gcd(gcdWork,m) gcd=g2.gcdCalc() gcd g2.gcdCalc() g2.gcdCalc g2 sum+=gcd sum gcd System.out.println(sum) System.out.println System.out System System.out sum String[] args args class Gcd {
	int targetA;
	int targetB;
	static int[] targetArray;
	
	public Gcd(int targetNumberA ,int targetNumberB) {
		this.targetA=targetNumberA;
		this.targetB=targetNumberB;
		this.targetArray = new int[2];
		targetArray[0] =targetA;
		targetArray[1] =targetB;
	}
	
	////最大公約数ユークリッドの互除法(int[A,B] )(return int)
	public static int gcdCalc(){
         int x;
         int y;
        if (targetArray[0] > targetArray[1]) {
            x = targetArray[0];
            y = targetArray[1];
        } else {
            x = targetArray[1];
            y = targetArray[0];
        }
        // ここからがユークリッドの互除法を用いた最大公約数を
        // 求める為の式
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return(y);
    }
	
//////最小公倍数(int[A,B] int )(return int)
	////gcdをgcdCalcで求めて代入
	public static int lcmCalc(int gcd) {
        int x;
        int y;
       if (targetArray[0] > targetArray[1]) {
           x = targetArray[0];
           y = targetArray[1];
       } else {
           x = targetArray[1];
           y = targetArray[0];
       }
       int lcm = (x*y)/gcd;
       return(lcm);
	}
	

} Gcd int targetA; targetA int targetB; targetB static int[] targetArray; targetArray public Gcd(int targetNumberA ,int targetNumberB) {
		this.targetA=targetNumberA;
		this.targetB=targetNumberB;
		this.targetArray = new int[2];
		targetArray[0] =targetA;
		targetArray[1] =targetB;
	} Gcd {
		this.targetA=targetNumberA;
		this.targetB=targetNumberB;
		this.targetArray = new int[2];
		targetArray[0] =targetA;
		targetArray[1] =targetB;
	} this.targetA=targetNumberA this.targetA this this.targetA targetNumberA this.targetB=targetNumberB this.targetB this this.targetB targetNumberB this.targetArray = new int[2] this.targetArray this this.targetArray new int[2] 2 targetArray[0] =targetA targetArray[0] targetArray 0 targetA targetArray[1] =targetB targetArray[1] targetArray 1 targetB int targetNumberA targetNumberA int targetNumberB targetNumberB ////最大公約数ユークリッドの互除法(int[A,B] )(return int)
	public static int gcdCalc(){
         int x;
         int y;
        if (targetArray[0] > targetArray[1]) {
            x = targetArray[0];
            y = targetArray[1];
        } else {
            x = targetArray[1];
            y = targetArray[0];
        }
        // ここからがユークリッドの互除法を用いた最大公約数を
        // 求める為の式
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return(y);
    } gcdCalc {
         int x;
         int y;
        if (targetArray[0] > targetArray[1]) {
            x = targetArray[0];
            y = targetArray[1];
        } else {
            x = targetArray[1];
            y = targetArray[0];
        }
        // ここからがユークリッドの互除法を用いた最大公約数を
        // 求める為の式
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return(y);
    } int x; x int y; y if (targetArray[0] > targetArray[1]) {
            x = targetArray[0];
            y = targetArray[1];
        } else {
            x = targetArray[1];
            y = targetArray[0];
        } targetArray[0] > targetArray[1] targetArray[0] targetArray 0 targetArray[1] targetArray 1 {
            x = targetArray[0];
            y = targetArray[1];
        } x = targetArray[0] x targetArray[0] targetArray 0 y = targetArray[1] y targetArray[1] targetArray 1 {
            x = targetArray[1];
            y = targetArray[0];
        } x = targetArray[1] x targetArray[1] targetArray 1 y = targetArray[0] y targetArray[0] targetArray 0 int tmp; tmp 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 return(y); (y) //////最小公倍数(int[A,B] int )(return int)
	////gcdをgcdCalcで求めて代入
	public static int lcmCalc(int gcd) {
        int x;
        int y;
       if (targetArray[0] > targetArray[1]) {
           x = targetArray[0];
           y = targetArray[1];
       } else {
           x = targetArray[1];
           y = targetArray[0];
       }
       int lcm = (x*y)/gcd;
       return(lcm);
	} lcmCalc {
        int x;
        int y;
       if (targetArray[0] > targetArray[1]) {
           x = targetArray[0];
           y = targetArray[1];
       } else {
           x = targetArray[1];
           y = targetArray[0];
       }
       int lcm = (x*y)/gcd;
       return(lcm);
	} int x; x int y; y if (targetArray[0] > targetArray[1]) {
           x = targetArray[0];
           y = targetArray[1];
       } else {
           x = targetArray[1];
           y = targetArray[0];
       } targetArray[0] > targetArray[1] targetArray[0] targetArray 0 targetArray[1] targetArray 1 {
           x = targetArray[0];
           y = targetArray[1];
       } x = targetArray[0] x targetArray[0] targetArray 0 y = targetArray[1] y targetArray[1] targetArray 1 {
           x = targetArray[1];
           y = targetArray[0];
       } x = targetArray[1] x targetArray[1] targetArray 1 y = targetArray[0] y targetArray[0] targetArray 0 int lcm = (x*y)/gcd; lcm (x*y)/gcd (x*y) x y gcd return(lcm); (lcm) int gcd gcd public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum =0;
		int gcdWork=0;
		int gcd =0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		}
		System.out.println(sum);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum =0;
		int gcdWork=0;
		int gcd =0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		}
		System.out.println(sum);
	}

} Main

import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int sum =0;
		int gcdWork=0;
		int gcd =0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int m=1;m<=k;m++) {
					Gcd g1 = new Gcd(i,j);
					gcdWork=g1.gcdCalc();
					Gcd g2 = new Gcd(gcdWork,m);
					gcd=g2.gcdCalc();
					sum+=gcd;
				}
			}
		}
		System.out.println(sum);
	}

}


class Gcd {
	int targetA;
	int targetB;
	static int[] targetArray;
	
	public Gcd(int targetNumberA ,int targetNumberB) {
		this.targetA=targetNumberA;
		this.targetB=targetNumberB;
		this.targetArray = new int[2];
		targetArray[0] =targetA;
		targetArray[1] =targetB;
	}
	
	////最大公約数ユークリッドの互除法(int[A,B] )(return int)
	public static int gcdCalc(){
         int x;
         int y;
        if (targetArray[0] > targetArray[1]) {
            x = targetArray[0];
            y = targetArray[1];
        } else {
            x = targetArray[1];
            y = targetArray[0];
        }
        // ここからがユークリッドの互除法を用いた最大公約数を
        // 求める為の式
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        return(y);
    }
	
//////最小公倍数(int[A,B] int )(return int)
	////gcdをgcdCalcで求めて代入
	public static int lcmCalc(int gcd) {
        int x;
        int y;
       if (targetArray[0] > targetArray[1]) {
           x = targetArray[0];
           y = targetArray[1];
       } else {
           x = targetArray[1];
           y = targetArray[0];
       }
       int lcm = (x*y)/gcd;
       return(lcm);
	}
	

}


