stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main() {

  int K;

  cin >> K;

  int answer = 0;

  int gcd, ok;

  for(int i = 1; i <= K; i++){

      for(int j = 1; j <= K; j++){

          for(int k = 1; k <= K; k++){

            gcd = 1;

            ok = 0;

            while(gcd <= i && gcd <= j && gcd <= k){

              if(i % gcd == 0 && j % gcd == 0 && k % gcd == 0){

                ok = gcd;

              }

              gcd++;             

            }

            answer += ok;

          }

      }

  }

  

  cout << answer << endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

using P = pair<int, int>; 

using ll = long long;



int main()

{

  int n;

  cin >> n;

  int ans = 0;

  for(int i = 1; i <= n; i++){

    for(int j = 1; j <= n; j++){

      for(int k = 1; k <= n; k++){

        ans += gcd(i, gcd(j, k));

      }

    }

  }

  cout << ans << endl;



  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using ll = long long int;

const int INF = (1<<30);

const ll INFLL = (1ll<<60);

const ll MOD = (ll)(1e9+7);



#define l_ength size



void mul_mod(ll& a, ll b){

	a *= b;

	a %= MOD;

}



void add_mod(ll& a, ll b){

	a = (a<MOD)?a:(a-MOD);

	b = (b<MOD)?b:(b-MOD);

	a += b;

	a = (a<MOD)?a:(a-MOD);

}



ll gcd(ll a, ll b){

	return ((b)?gcd(b,a%b):a);

}



int main(void){

	ll i,j,k,n,ans=0ll;

	std::cin >> n;

	for(i=1; i<=n; ++i){

		for(j=1; j<=n; ++j){

			for(k=1; k<=n; ++k){

				ans += gcd(i,gcd(j,k));

			}

		}

	}

	std::cout << ans << std::endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>



using ll = long long int;

const int INF = (1<<30);

const ll INFLL = (1ll<<60);

const ll MOD = (ll)(1e9+7);



#define l_ength size



void mul_mod(ll& a, ll b){

	a *= b;

	a %= MOD;

}



void add_mod(ll& a, ll b){

	a = (a<MOD)?a:(a-MOD);

	b = (b<MOD)?b:(b-MOD);

	a += b;

	a = (a<MOD)?a:(a-MOD);

}



ll c[100100];



ll rwpw(ll a, ll p){

	ll ret = 1ll;

	while(p){

		if(p%2){

			mul_mod(ret,a);

		}

		mul_mod(a,a);

		p /= 2;

	}

	return ret;

}



int main(void){

	ll n,k,i,j,ans=0ll;

	n = 3;

	std::cin >> k;

	for(i=1ll; i<=k; ++i){

		add_mod(c[i],i);

		add_mod(ans,c[i]*rwpw(k/i,n)%MOD);

		for(j=i*2; j<=k; j+=i){

			add_mod(c[j],MOD-c[i]);

		}

	}

	std::cout << ans << std::endl;

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main() {

  int N;

  cin >> N;



  long ans = 0;

  for (int a = 1; a <= N; a++) {

    for (int b = 1; b <= N; b++) {

      for (int c = 1; c <= N; c++) {

        ans += gcd(gcd(a, b), c);

      }

    }

  }



  cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



#define MAX_N 200



int main() {

  int N;

  cin >> N;



  int gcd[MAX_N + 1][MAX_N + 1];



  for (int i = 1; i <= N; i++) {

    gcd[i][i] = gcd[0][i] = gcd[i][0] = i;

    for (int j = i + 1; j <= N; j++) {

      gcd[i][j] = gcd[j][i] = gcd[i][j % i];

    }

  }



  long ans = 0;

  for (int a = 1; a <= N; a++) {

    for (int b = 1; b <= N; b++) {

      for (int c = 1; c <= N; c++) {

        ans += gcd[gcd[a][b]][c];

      }

    }

  }



  cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int K;



int main() {

    cin>>K;

    long ans=0;

    for (int i=1; i<=K; i++) {

        for (int j=1; j<=K; j++) {

            int codiv;

            for (int k=1; k<=min(i,j); k++) {

                if (i%k==0 && j%k==0) codiv=k;

            }

            for (int k=1; k<=K; k++) {

                int codiv2;

                for (int l=1; l<=min(i,j); l++) {

                    if (k%l==0 && codiv%l==0) codiv2=l;

                }

                ans+=codiv2;

            }

        }

    }

    cout<<ans<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int K;



int main() {

    cin>>K;

    long ans=0;

    for (int i=1; i<=K; i++) {

        for (int j=1; j<=K; j++) {

            int codiv;

            codiv=gcd(i,j);

            for (int k=1; k<=K; k++) {

                int codiv2;

                codiv2=gcd(codiv,k);

                ans+=codiv2;

            }

        }

    }

    cout<<ans<<endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h> 

using namespace std;

using ll = long long;



#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);



int gcd(int a, int b) {

    if(a%b==0) {

        return b;

    }

    return gcd(b,a%b);

}



int ans;

int k;

void dfs(vector<int> s) {

    if(s.size()==3) {

        ans+=gcd(gcd(s[0],s[1]),s[2]);

        //cout<<s[0]<<' '<<s[1]<<' '<<s[2]<<endl;

        return;

    }



    for(int i=1;i<=k;i++) {

        s.push_back(i);

        dfs(s);

        s.pop_back();

    }



    return;

        

}



int main() {

    fast_io;

    ans=0;



    cin>>k;



    vector<int> s;



    dfs(s);

    cout<<ans<<endl;





}






// Optimized solution to the same problem (faster):
#include<bits/stdc++.h> 

using namespace std;

using ll = long long;



#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);



int gcd(int a, int b) {

    while(b != 0) {

        int r=a%b;

        a=b;

        b=r;

    }

    return a;



}



int ans;

int k;

//void dfs(vector<int> s) {

//    if(s.size()==3) {

//        ans+=gcd(gcd(s[0],s[1]),s[2]);

//        //cout<<s[0]<<' '<<s[1]<<' '<<s[2]<<endl;

//        return;

//    }

//

//    for(int i=1;i<=k;i++) {

//        s.push_back(i);

//        dfs(s);

//        s.pop_back();

//    }

//

//    return;

//        

//}



int main() {

    fast_io;

    ans=0;



    cin>>k;



    for(int i=1;i<=k;i++) {

        for(int j=1;j<=k;j++) {

            for(int l=1;l<=k;l++) {

                ans+=gcd(gcd(i,j),l);

            }

        }

    }



    cout<<ans<<endl;





}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int gcd(int a,int b,int c){

  long long ans=1;

  for(int i=1;i<=min(min(a,b),c);i++){

    if(a%i==0 && b%i==0 && c%i==0) ans=i;

  }

  return ans;

}



int main() {

  long long n;

  cin>>n;

  long long ans=0;

  for(int i=1;i<=n;i++){

    for(int j=1;j<=n;j++){

      for(int k=1;k<=n;k++){

        ans+=gcd(i,j,k);

      }

    }

  }

  cout<<ans;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int gcd(int a,int b){

    if(b==0) return a;

    return gcd(b,a%b);

}

int main(){

    int k;

    cin>>k;

    long long ans=0;

    rep(i,k){

        rep(j,k){

            rep(l,k){

                ans+=gcd((i+1),gcd(j+1,l+1));

            }

        }

    }

    cout<<ans;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int gcd(int a,int b){

    int GCD=1;

    rep(i,min(a,b)){

        if(a%(i+1)==0 && b%(i+1)==0) GCD=i+1;

    }

    return GCD;

}

int main(){

    int k;

    cin>>k;

    long long ans=0;

    rep(i,k){

        rep(j,k){

            rep(l,k){

                ans+=gcd((i+1),gcd(j+1,l+1));

            }

        }

    }

    cout<<ans;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int gcd(int a,int b){

    if(b==0) return a;

    return gcd(b,a%b);

}

int main(){

    int k;

    cin>>k;

    long long ans=0;

    rep(i,k){

        rep(j,k){

            rep(l,k){

                ans+=gcd((i+1),gcd(j+1,l+1));

            }

        }

    }

    cout<<ans;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define ll long long



int gcd(int i,int j,int k){

for(int ii=i;ii>=1;ii--){

    if(i%ii==0&&j%ii==0&&k%ii==0)

        return ii;

}

}



int main(){

    int n;

    cin>>n;

    long long sum=0;

    for(int i=1;i<=n;i++)

        for(int j=1;j<=n;j++)

        for(int k=1;k<=n;k++){

        sum+=gcd(i,j,k);

    }

    cout<<sum<<endl;

    return 0;





}




// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long

#define pii pair<int,int>

#define pll pair<ll,ll>

#define pil pair<int,ll>

#define pli pair<ll,int>

#define mod 1000000007

#define mp make_pair

#define pb push_back

#define ff first

#define ss second

int main(){

FASTIO  

ll k;

cin>>k;

ll ans=0;

for(ll i=1;i<=k;i++){

  for(ll j=1;j<=k;j++){

     for(ll p=1;p<=k;p++){

        ans+=(ll)(__gcd(i,__gcd(j,p)));

     }

  }

}

cout<<ans;

return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)

#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)

#define REP(i,n) for (int i=0;i<(n);i++)

#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

typedef long long LL;

LL K;

LL gcd (int a,int b){

	if(a<b)return gcd(b,a);

	if(b==0){

		return a;

	}

	return gcd(b,a%b);

}



int main(){

	cin>>K;

	LL ans=0;

	REP(i,K){

		REP(j,K){

			REP(k,K){

				LL a=gcd(i+1,j+1);

				ans+=gcd(a,k+1);

			}

		}

	}

	cout<<ans<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)

#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)

#define REP(i,n) for (int i=0;i<(n);i++)

#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

typedef long long LL;

int N;

int K;

LL MOD=1e9+7;

LL ans[100011];



LL pow(LL x, LL b){

	LL ans=1;

	LL now=x;

	while(b!=0){

		if(b%2==0){

			ans*=now;

			ans%=MOD;

		}

		now*=now;

		now%=MOD;

		b/=2;

	}

	return ans;

}



int main(){

	cin>>K;

	N=3;

	REP(i,K+1){

		ans[i]=0;

	}

	for(int i=K;i>=1;i--){

		vector<int>v;

		v.clear();

		for(int j=1;j*j<=i;j++){

			if(i%(j)==0){

				v.push_back(j);

				v.push_back(i/j);

			}

		}

		sort(v.begin(),v.end());

		v.erase(unique(v.begin(),v.end()),v.end());

		LL now=K/i;

		LL tmp=pow(now,N);

		//cout<<"now"<<now<<" "<<N<<" "<<tmp<<endl;

		ans[i]+=tmp;

		ans[i]%=MOD;

		/*REP(j,3){

			cout<<ans[j]<<endl;

		}*/

		REP(j,v.size()){

			if(i!=v[j]){

				ans[v[j]]+=MOD-ans[i];

				ans[v[j]]%=MOD;

			}

		}

		/*REP(j,10){

			cout<<ans[j]<<endl;

		}

		cout<<endl;

		*/

	}

	LL answer=0;

	REP(i,K+1){

		answer+=(ans[i]*i);

		answer%=MOD;

	}

	cout<<answer<<endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <vector>

#include <deque>

#include <algorithm>

#include <set>

#include <map>

#include <bitset>

#include <cmath>

#include <functional>

#include <iomanip>

#define vll vector<ll>

#define vvvl vector<vvl>

#define vvl vector<vector<ll>>

#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))

#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));

#define re(c, b) for(ll c=0;c<b;c++)

#define all(obj) (obj).begin(), (obj).end()

typedef long long int ll;

typedef long double ld;

using namespace std;



ll gcd(ll a, ll b){

  if(b<a) swap(a, b);

  ll r = a % b;

  if(r==0) return b;

  while(r!=0) r = a % b, a = b, b = r;

  return a;

}

int main(int argc, char const *argv[]) {

  ll n;std::cin >> n;

  ll s = 0;

  for(int i=1;i<=n;i++){

    for(int j=1;j<=n;j++){

      for(int k=1;k<=n;k++){

        s += gcd(gcd(i, j), k);

      }

    }

  }

  std::cout << s << '\n';

  return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

using namespace std;



int main(int argc, char const *argv[]) {

  int k;scanf("%d", &k);

  int ans = 0;

  vector<int> num(k+1, 0);

  for(int i=k;i>0;i--){

    num[i] += (k/i)*(k/i)*(k/i);

    for(int j=2;j*j<=i;j++){

      if(i%j!=0) continue;

      num[j] -= num[i];

      if(j*j!=i) num[i/j] -= num[i];

    }

    if(i!=1) num[1] -= num[i];

    ans += num[i] * i;

  }

  printf("%d\n", ans);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int gcd(int a, int b) {

    if(b == 0) return a;

    else return gcd(b, a%b);

}



int gcd(int a, int b, int c) {

    return gcd(a, gcd(b,c));

}



int main() {

    int K;

    cin >> K;

    long long res = 0LL;

    for(int a = 1; a <= K; ++a) {

        for(int b = 1; b <= K; ++b) {

            for(int c = 1; c <= K; ++c) {

                res += gcd(a,b,c);

            }

        }

    }

    cout << res << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



const int MAX_N = 210;

int GCD[MAX_N][MAX_N];



int gcd(int a, int b) {

    if(b == 0) return a;

    else return gcd(b, a%b);

}



int main() {

    int K;

    cin >> K;

    for(int i = 1; i <= K; ++i) {

        for(int j = 1; j <= i; ++j) {

            GCD[i][j] = GCD[j][i] = gcd(i,j);

        }

    }

    long long res = 0LL;

    for(int a = 1; a <= K; ++a) {

        for(int b = 1; b <= K; ++b) {

            for(int c = 1; c <= K; ++c) {

                res += GCD[a][GCD[b][c]];

            }

        }

    }

    cout << res << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main(){

  int K;

  cin >> K;

  int64_t ans = 0;

  for(int i=1; i<=K; i++){

    for(int j=1; j<=K; j++){

      for(int k=1; k<=K; k++){

        int x = gcd(i,j);

        ans += gcd(x,k);

      }

    }

  }

  cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

int main(){

  int K;

  cin >> K;

  int64_t ans = 0;

  for(int i=1; i<=K; i++){

    for(int j=i; j<=K; j++){

      for(int k=j; k<=K; k++){

        int x = gcd(gcd(i,j),k);

        if(i == j && j == k){

          ans += x;

        }

        else if((i == j && j != k) || (i != j && j == k)){

          ans += x*3;

        }

        else{

          ans += x*6;

        }

      }

    }

  }

  cout << ans << endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main()

{

    int n,i,ans=0,count=0,j,in[100],m,low2,low1,k,l;



    cin >> n ;

    for(i=1; i<=n; i++)

    {

        for(j=1; j<=n; j++)

        {

            for(k=1; k<=n; k++)

            {

                low1 = min(i,j);

                low2 = min(low1,k);

                for(l=low2;l>0;l--)

                {

                    if(i%l == 0 && j%l == 0 && k%l == 0 )

                    {

                        ans = ans + l;

                        break;

                    }

                }

            }

        }

    }

    cout << ans;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<math.h>

#include<stack>

#include<queue>

#include<string>

#include<deque>

#include<set>

#include<vector>

#include<map>

using namespace std;

long long sum=0;

int gcd(int a,int b,int c)

{

    int x=0;

    if(a<b)

        swap(a,b);

    while(a%b!=0)

    {

        x=a%b;

        a=b;

        b=x;

    }

    if(b<c)

        swap(b,c);

    while(b%c!=0)

    {

        x=b%c;

        b=c;

        c=x;

    }

    return c;

}

int main()

{

    int k,a=1,b=1,c=1;

    scanf("%d",&k);

    for(a=1,b=1,c=1;a<=k&&b<=k&&c<=k;)

    {

        sum+=gcd(a,b,c);

        for(int i=1;a+i<=k;i++)

        {

            sum+=gcd(a+i,b,c);

        }

        for(int i=1;b+i<=k;i++)

        {

            sum+=gcd(a,b+i,c);

        }

        for(int i=1;c+i<=k;i++)

        {

            sum+=gcd(a,b,c+i);

        }

        for(int i=1;a+i<=k;i++)

        {

            for(int j=1;b+j<=k;j++)

                sum+=gcd(a+i,b+j,c);

        }

        for(int i=1;a+i<=k;i++)

        {

            for(int j=1;c+j<=k;j++)

                sum+=gcd(a+i,b,c+j);

        }

        for(int i=1;b+i<=k;i++)

        {

            for(int j=1;c+j<=k;j++)

                sum+=gcd(a,b+i,c+j);

        }

        a++;

        b++;

        c++;

    }

    printf("%lld\n",sum);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

using pp=pair<int,int>;



int gcd(int a, int b, int c) {

  int m, n;

  for (int i=1; i<=min(a,b); i++) {

    if (a%i==0 && b%i==0) {m=i;}

  }

  for (int i=1; i<=min(m,c); i++) {

    if (m%i==0 && c%i==0) {n=i;}

  }

  return n;

}





int main() {

  int K, S=0;

  cin >> K;

  for (int i=1; i<=K; i++) {

    for (int j=1; j<=K; j++) {

      for (int k=1; k<=K; k++) {

        S+=gcd(i,j,k);

      }

    }

  }

  cout << S << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using pp=pair<int,int>;



int gcd(int a, int b, int c) {

  int m, n;

  while (b!=0) {

    m=a%b;

    a=b;

    b=m;

  }

  m=a;

  

  while (c!=0) {

    n=m%c;

    m=c;

    c=n;

  }

  n=m;

  return n;

}





int main() {

  int K, S=0;

  cin >> K;

  for (int i=1; i<=K; i++) {

    for (int j=1; j<=K; j++) {

      for (int k=1; k<=K; k++) {

        S+=gcd(i,j,k);

      }

    }

  }

  cout << S << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;



int gcd(int x, int y)

{

  return y ? gcd(y,x%y) : x;

}



int main()

{

  int k; cin >> k;

  ll ans = 0;

  for (int p=1; p<=k; p++)

    for (int q=1; q<=k; q++)

      for (int r=1; r<=k; r++)

        ans += gcd(gcd(p, q), r);

  cout << ans << endl;

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;



int gcd(int x, int y)

{

  return y ? gcd(y,x%y) : x;

}



int main()

{

  int k; cin >> k;

  ll ans = 0;

  for (int p=1; p<=k; p++)

  {

    ans += p;

    for (int q=p+1; q<=k; q++)

    {

      ans += gcd(p, q) * 6;

      for (int r=q+1; r<=k; r++)

        ans += gcd(gcd(p, q), r) * 6;

    }

  }

  cout << ans << endl;

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

#define rep(i,n) for(int i=0;i<int(n);i++)

#define rep1(i,n) for(int i=1;i<=int(n);i++)

#define per(i,n) for(int i=int(n)-1;i>=0;i--)

#define per1(i,n) for(int i=int(n);i>0;i--)

#define foreach(i,n) for(auto &&i:n)

#define all(x) (x).begin(),(x).end()

#define SORT(x) sort(all(x))

#define REV(x) reverse(all(x))

#define MAX(x) *max_element(all(x))

#define MIN(x) *min_element(all(x))

#define LOWitr(x, n) lower_bound(all(x), n)

#define UPRitr(x, n) upper_bound(all(x), n)

#define cii(x) int x;cin >> x

#define cill(x) LL x;cin >> x

#define cis(x) string x;cin >> x

#define co(x) cout << x << endl

#define dump(x)  cout << #x << " = " << (x) << endl

#define truecheck assert

#define pb push_back

#define mp make_pair

#define F first

#define S second

using namespace std;

typedef long long LL;

typedef long long int64;

typedef vector<int> VI;

typedef vector<LL> VL;

typedef vector<VI> VVI;

typedef vector<string> VS;

typedef pair<int, int> PII;

template<class T,class U>bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}

template<class T,class U>bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}

template<class T,class U>void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}

const int INF = 1e9, MOD = 1e9 + 7;

const LL LLINF = 1e16;



int main() {

    fastcin();

    cout << fixed << setprecision(10);

    cii(k);

    int64 ans=0;

    function<int64(int64, int64)> gcd = [&gcd](int64 x, int64 y){

        return !y ? x : gcd(y, x % y);

    };

    rep1(i, k){

        rep1(j, k){

            rep1(y, k){

                ans += gcd(gcd(i, j), y);

            }

        }

    }

    co(ans);



    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <iomanip>

#include <string>

#include <string.h>

#include <vector>

#include <math.h>

#include <queue>

#include <map>

#define INF 100000000



const int MOD = 1e9+7;

typedef long long ll;

using namespace std;

const ll M = 998244353;



ll gcd(ll a, ll b) {

    ll tmp, r;

    if(a<b) {

        tmp = a;

        a = b;

        b = tmp;

    }



    r = a%b;

    while(r!=0) {

        a = b;

        b = r;

        r = a%b;

    }



    return b;

}



int main(void) {

	ll k, sum=0;

	cin >> k;

	for(ll a=1;a<k+1;a++) {

	  for(ll b=1;b<k+1;b++) {

		for(ll c=1;c<k+1;c++) {

          sum += gcd(gcd(a,b), c);

		}

	  }	

	}



	cout << sum << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;



int gcd(int p,int q)

{

    if(q==0) return p;

    return gcd(q,p%q);

}



int main(void)

{

    int k,sum=0,g;

    cin >> k;

    for(int i=1;i<=k;i++)

    {

        for(int j=1;j<=k;j++)

        {

            g = gcd(i,j);

            for(int l=1;l<=k;l++)

            {

                sum+=gcd(g,l);

            }

        }

    }

    cout << sum;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

int e(int p,int q)

{

    if(q==0)

        return p;

    return e(q,p%q);

}

int main(void)

{

    int k,sum=0;

    scanf("%d" ,&k);

    for(int i=1;i<=k;i++)

        for(int j=1;j<=k;j++)

        {

            int g=e(i,j);

            for(int l=1;l<=k;l++)

                sum+=e(g,l);

        }

    printf("%d" ,sum);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



#define ll long long



int main()

{

    ll n,a,b;

    cin>>n;

    if(n==1)

        cout<<"Hello World"<<endl;

    else{

        cin>>a>>b;

        cout<<a+b<<endl;

    }

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()

{

    int n,a,b;

    scanf("%d%d%d", &n,&a,&b);



    if(n==1)

        printf("Hello World\n");

    if(n==2)

        printf("%d\n", a+b);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;

int main()

{

    int X,J,K,sum;

    scanf("%d",&X);

    if(X==1)

    {

        printf("Hello World");

    }

    else if(X==2)

    {

        scanf("%d%d",&J,&K);

        sum=J+K;

        printf("%d",sum);

      

    }





}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()

{

    int n,a,b;

    scanf("%d%d%d", &n,&a,&b);



    if(n==1)

        printf("Hello World\n");

    if(n==2)

        printf("%d\n", a+b);

}


// Fastest known solution for this problem: