Problem:
Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692

Solution in Rust (1.42.0) (judge verdict: Accepted)

#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::fastout;
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
//use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
       k: usize
    }
    let mut g = vec![vec![1; 201]; 201];
    for i in 1..201 {
        for j in 1..201 {
            if i == j {
                g[i][j] = i;
            }
            if i > j {
                g[i][j] = g[j][i];
            }
            g[i][j] = gcd(j, i);
        }
    }
    let mut ans = 0;
    for i in 1..k + 1 {
        for j in 1..k + 1 {
            for l in 1..k + 1 {
                ans += g[i][g[j][l]];
            }
        }
    }
    println!("{}", ans);
    //    // 同じ数
    //    let ans1 = k * (k + 1) / 2;
    //    // 2つが同じ数。
    //    // 各ペアの6倍。
    //    let mut ans2 = 0;
    //    for i in 1..k {
    //        for j in i + 1..k + 1 {
    //            ans2 += g[i][j];
    //        }
    //    }
    //    ans2 *= 6;
    //    let mut ans3 = 0;
    //    for i in 1..k - 1 {
    //        for j in i + 1..k {
    //            for l in j + 1..k + 1 {
    //                ans3 += g[i][g[j][l]];
    //            }
    //        }
    //    }
    //    ans3 *= 6;
    //
    //    println!("{}", ans1 + ans2 + ans3);
}

fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

//fn gcd3(a: u64, b: u64, c: u64) -> u64 {
//    gcd(a, gcd(b, c))
//}