/*
 * FileName:     C
 * CreatedDate:  2020-04-12 21:49:50 +0900
 * LastModified: 2020-04-12 21:53:18 +0900
 */

#include <stdio.h>
int gcd(int x,int y){
    int r;
    while((r=x%y)!=0){
        x=y;
        y=r;
    }
    return y;
}
int main(void){
    int n,count=0;
    scanf("%d",&n);
    for(int i=1;i<n+1;i++){
        for(int j=1;j<n+1;j++){
            for(int k=1;k<n+1;k++){
                int ngcd = gcd(i,j);
                int nngcd = gcd(ngcd,k);
                count+=nngcd;
                
            }
        }
    }
    printf("%d\n",count);
    return 0;
}
