jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	split := strings.Split(s.Text(), " ")

	d := make([]int, k)
	for i, s := range split {
		d[i], _ = strconv.Atoi(s)
	}

	base := []int{0, 1, 2, 3, 4, 5, 6, 78, 8, 9}
	fav := make([]int, 0, len(base)-k)
l1:
	for _, b := range base {
		for _, v := range d {
			if b == v {
				continue l1
			}
		}
		fav = append(fav, b)
	}

l2:
	for i := n; i < 10000; i++ {
		var ns []int
		ns = digit(i, ns)

		for j := 0; j < len(ns); j++ {
			if ns[j] == 0 {
				continue
			}

			var valid bool
			for _, v := range fav {
				if ns[j] == v {
					valid = true
				}
			}
			if !valid {
				continue l2
			}
		}

		fmt.Printf("%d", i)
		break
	}
}

func digit(i int, list []int) []int {
	if i > 0 {
		return digit(i/10, append(list, i%10))
	}
	return list
}
//  [ruby]
N,K = gets.split.map(&:to_i)
D = gets.split.map(&:to_i)

ans = []
nums = 10.times.to_a - D
N.to_s.chars.reverse_each do |s|
  n = s.to_i
  m = nums.find {|m| n <= m }# || nums[0]
  ans.fill(nums[0]) if m && n < m
  ans.unshift(m)
end
ans.size.times.reverse_each do |i|
  next if ans[i]
  if i == 0
    ans.fill(nums[0]).unshift(nums.find {|m| 0 < m })
  else
    j = i - 1
    ans[i] = nums[0]
    ans[j] = nums.find {|m| ans[j] < m } if ans[j]
  end
end
puts ans.join
//  [ruby]
N, = gets.split
D = gets.split.map(&:to_i)

digits = ([*0..9]-D).sort
nz = digits[0]!=0 ? digits[0] : digits[1]

borrow = N.size-2-(N.each_char.reverse_each.with_index.inject(nil){|borrow, ci|
	n, i = ci[0].ord-'0'.ord, ci[1]
	m = digits.find{|d| borrow==i-1 ? n<d : n<=d }
	next m.nil? ? i : borrow
}||-2)
over = borrow==-1
p N.each_char.with_index.inject(borrow==-1?nz:0){|a,ci|
	n, i = ci[0].ord-'0'.ord, ci[1]
	m = over ? digits[0] : digits.find{|d| borrow == i ? n<d : n<=d }
	over ||= n<m
	next a*10 + m
}
//  [ruby]
N, K = gets.chomp.split
Ds = gets.chomp.split
Es = [*'0'..'9'] - Ds
tbl = {}
Es.each { |d| tbl[d] = true }

ms = ''
carry = false
N.reverse.chars do |c|
  c2 = c.dup
  c2.next! if carry
  c2.next! until tbl[c2] || c2.size > 1
  if c2.size == 1
    carry = false
  else
    c2 = Es[0]
    carry = true
  end
  ms = Es[0] * ms.size if c2 != c
  ms += c2
end
if carry
  ms += (Es[0] == '0' ? Es[1] : Es[0])
end

puts ms.reverse
//  [ruby]
n, k = gets.split.map &:to_i
d = gets.split.map &:to_i
digits = [*0..9] - d
l = digits.size
x = [0]
val = ->x{ x.inject(0) { |s, i| s * 10 + digits[i] } }
while val[x] < n
  if (x.size-1).downto(0).all? { |j|
    x[j] += 1
    if x[j] == l
      x[j] = 0
    else
      false
    end
    }
    x.unshift 1
  end
end

p val[x]
//  [ruby]
n, k = gets.split.map(&:to_i)
darr = gets.split.map(&:to_i)
uarr = (0..9).to_a - darr

num = -1
arr = Array.new(10, 0)
uarr.each do |n|
  (n - num).times do |j|
    arr[num + j + 1] = n
  end
  num = n
end

flag = false
snum_arr = n.to_s.chars
snum_arr.length.times do |i|
  num = snum_arr[i].to_i
  snum_arr[i] = flag ? arr[0].to_s : arr[num].to_s
  flag ||= arr[num] != num
end

snum_arr.unshift(arr[1].to_s) if snum_arr[0] == "0"
puts snum_arr.join
//  [ruby]
n, k = gets.split.map(&:to_i)
darr = gets.split.map(&:to_i)
uarr = (0..9).to_a - darr

arr = []
uarr.each do |n|
  l = arr.length
  (n - l + 1).times do |j|
    arr[l + j] = n
  end
end
l = arr.length
(10 - l).times do |i|
  arr[l + i] = 0
end

flag = false
snum_arr = n.to_s.chars
snum_arr.length.times do |i|
  num = snum_arr[i].to_i
  snum_arr[i] = flag ? arr[0].to_s : arr[num].to_s
  flag ||= arr[num] != num
end

snum_arr.unshift(arr[1].to_s) if snum_arr[0] == "0"
puts snum_arr.join
//  [rust]
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<u64>();
    let (n, _) = (line[0], line[1]);
    let d = read_as_vec::<u64>();

    'outer: for i in 1..n*10+1{
        if i < n{
            continue;
        }

        let mut x = i;
        while x > 0{
            if d.contains(&(x%10)){
                continue 'outer;
            }
            x /= 10;
        }
        println!("{}", i);
        return;
    }

    // let line = read_as_string();
    // let line: Vec<&str> = line.split_ascii_whitespace().collect::<Vec<&str>>();
    // let n: String = String::from(line[0]);
    // let k: u64 = u64::from_str(line[1]).unwrap();
    // let d = read_as_vec::<u64>();

    // let mut ans = 0;
    // let mut is_already_bigger = false;
    // for c in n.chars(){
    //     match d.iter().filter(|x| **x>= c.to_digit(10).unwrap() as u64).nth(0){
    //         Some(number) => {
    //             if is_already_bigger{
    //             }
    //             ans = ans*10+number;
    //             if *number > c.to_digit(10).unwrap() as u64{
    //                 is_already_bigger = true;
    //             }
    //         },
    //         None => {
    //             ans = ans*10
    //         }
    //     }
    // }

    // if ans >= n.parse().unwrap(){
    //     println!("{}", ans);
    //     return;
    // }
}
//  [rust]
use std::io;

fn choose_digit(available_digits: &Vec<bool>, lower_digits: &mut Vec<usize>, d: usize) -> usize {
    if available_digits[d] {
        // println!("available: {}", d);
        lower_digits.push(d);
        return 0;
    }
    clear_lower_digits(&available_digits, lower_digits);
    // println!("cleared");
    for i in d+1..10 {
        if available_digits[i] {
            // println!("chosen: {}", i);
            lower_digits.push(i);
            return 0;
        }
    }
    lower_digits.push(0);
    return 1;
}

fn clear_lower_digits(available_digits: &Vec<bool>, ds: &mut Vec<usize>) {
    let mut d = 0;
    for i in 0..10 {
        // println!("i: {}", i);
        if available_digits[i] {
            d = i;
            break
        }
    }
    // println!("lowest digit: {}", d);
    let len = ds.len();
    for i in 0..len {
        ds[i] = d;
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut iter = input.split_whitespace();
    let mut n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let mut available_digits = vec![true; 10];
    let mut line = String::with_capacity(2 * k);
    io::stdin().read_line(&mut line).unwrap();
    for token in line.split_whitespace() {
        let d: usize = token.parse().unwrap();
        available_digits[d] = false;
    }
    let mut digits = Vec::with_capacity(5);
    let mut carry = 0;
    while n > 0 {
        let d = n % 10 + carry;
        if d <= 9 {
            carry = choose_digit(&available_digits, &mut digits, d);
        } else {
            choose_digit(&available_digits, &mut digits, 0);
            carry = 1;
        }
        n = n / 10;
    }
    if carry > 0 {
        choose_digit(&available_digits, &mut digits, carry);
    }
    if digits.len() == 0 {
        println!("0");
        return
    }
    for d in digits.iter().rev() {
        print!("{}", d);
    }
    println!("");
}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        d: [usize;k],
    }

    let mut ok: bool = true;
    let mut not_d: Vec<usize> = Vec::new();

    for i in 0..10 {
        for j in 0..k {
            if i!=d[j] {
                continue;
            } else {
                ok = false;
            }
        }
        if ok {
            not_d.push(i);
        } else {
            ok = true;
        }
    }
    ok = false;
    let nl = not_d.len();
    // debug!(not_d);
    for i in n..100000 {
        let mut x = i;
        while x!=0 {
            let r = x%10;
            if ok {
                ok = false;
            }
            for j in 0..nl {
                if r==not_d[j] {
                    ok = true;
                    break;
                } 
                // debug!(not_d[j]);
            }
            x /= 10;
            // debug!(r);
            // debug!(ok);
        }
        if ok==true {
            println!("{}", i);
            return;
        } 
    }

}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        d: [usize;k],
    }

    let mut ok: bool = true;
    let mut not_d: Vec<usize> = Vec::new();

    for i in 0..10 {
        for j in 0..k {
            if i!=d[j] {
                continue;
            } else {
                ok = false;
            }
        }
        if ok {
            not_d.push(i);
        } else {
            ok = true;
        }
    }
    ok = false;
    let nl = not_d.len();
    // debug!(not_d);
    let mut i = n;
    loop {
        let mut x = i;
        while x!=0 {
            let r = x%10;
            if ok {
                ok = false;
            }
            for j in 0..nl {
                if r==not_d[j] {
                    ok = true;
                    break;
                } 
                // debug!(not_d[j]);
            }
            x /= 10;
            // debug!(r);
            // debug!(ok);
        }
        if ok==true {
            println!("{}", i);
            return;
        } else {
            i += 1; 
        }
    }

}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        d: [usize;k],
    }

    let mut ok: bool = true;
    let mut not_d: Vec<usize> = Vec::new();

    for i in 0..10 {
        for j in 0..k {
            if i!=d[j] {
                continue;
            } else {
                ok = false;
            }
        }
        if ok {
            not_d.push(i);
        } else {
            ok = true;
        }
    }
    ok = false;
    let nl = not_d.len();
    // debug!(not_d);
    for i in n..10000 {
        let mut x = i;
        while x!=0 {
            let r = x%10;
            if ok {
                ok = false;
            }
            for j in 0..nl {
                if r==not_d[j] {
                    ok = true;
                    break;
                } 
                // debug!(not_d[j]);
            }
            x /= 10;
            // debug!(r);
            // debug!(ok);
        }
        if ok==true {
            println!("{}", i);
            return;
        } 
    }

}
//  [swift]
//
//  main.swift
//  Atcoder
//
//  Created by Louis Joe Shen on 2020/7/17.
//  Copyright © 2020 Louise Joe Shen. All rights reserved.
//

import Foundation

var input = readLine()
var input2 = readLine()
var inputs = input!.components(separatedBy: " ")
var inputs2 = input2!.components(separatedBy: " ")

var N = Int(inputs[0])!
var K = Int(inputs[1])!

var D : [Int] = [Int]()

for i in 0 ..< K {
    D.append(Int(inputs2[i])!)
}

for i in N ... 666666 {
    if(isLike(number: i)){
        print(i)
        break;
    }
}
func isLike(number: Int) -> Bool {
    let delta = String(number)
    for c in delta {
        for dig in D {
            if(Int(String(c))! == dig){
                return false
            }
        }
    }
    return true;
}
//  [swift]
let N = readLine()!.characters.split(" ").map{Int(String($0))!}[0]
let D = readLine()!.characters.split(" ").map{String($0)}
for i in N..<100000 {
    var flag = false
    for c in D {
        if String(i).characters.contains(Character(c)) {
            flag = false
            break
        } else {
            flag = true
        }
    }
    if flag {
        print(i)
        break
    }
}
//  [swift]
import Foundation

            let values = readLine()!.characters.split{ x in x == " "}.map{Int(String($0))!}
            let N = values[0]
            let D = readLine()!.characters.split{ x in x == " "}.map{Int(String($0))!}

            for i in N ... 10000 {
                let str = String(i)
                for d in D {
                    if str.rangeOfString(String(d)) != nil {
                        continue
                    } else {
                        print(str)
                    }
                }
            }
//  [swift]
            let values = readLine()!.characters.split{ x in x == " "}.map{Int(String($0))!}
            let N = values[0]
            let D = readLine()!.characters.split{ x in x == " "}.map{Int(String($0))!}

            for i in N ... 10000 {
                let str = String(i)
                for d in D {
                    if str.rangeOfString(String(d)) != nil {
                        continue
                    } else {
                        print(str)
                    }
                }
            }
//  [swift]
            let values = readLine()!.characters.split{ x in x == " "}.map{Int(String($0))!}
            let N = values[0]
            let D = readLine()!.characters.split{ x in x == " "}.map{Int(String($0))!}

            for i in N ... 10000 {
                let str = String(i)
                for d in D {
                    if str.rangeOfString(String(d)) != nil {
                        continue
                    } else {
                        print(str)
                        return
                    }
                }
            }
//  [typescript]
import * as fs from 'fs'
const reader = (s: string) => s.split('\n')

function Main(input: string) {
  const [tmp, tmp2] = reader(input)
  const [N, K] = tmp.split(' ').map(x => parseInt(x, 10))
  const D = tmp2.split(' ')
  let ans = N

  while (1) {
    let count = 0
    for (const i of D) {
      if (ans.toString().indexOf(i) !== -1) {
        break
      }
      count++
    }
    if (count === K) {
      break
    }
    ans += 1
  }
  console.log(ans)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))
//  [typescript]
function main(input: string) {
  let num: number = Number(input.split(" ")[0]);
  const arrD: string[] = input
    .split("\n")
    .slice(1)
    .filter((val: string) => val !== "");
  const regD: RegExp = new RegExp(`[${arrD.join("")}]`, "g");
  while (num.toString().match(regD) != null) {
    num += 1;
  }
  console.log(num);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8").split(/\n/);

// C-こだわり者いろはちゃん

let price = +input[0].split(' ')[0];
const dislikeNumbers = input[1].split(' ');
let flag: boolean = true;




while (flag === true) {
    flag = false;
    let target = String(price).split('');
    for (let i = 0; i < dislikeNumbers.length; i++) {
        if (target.indexOf(dislikeNumbers[i]) !== -1) {
            flag = true;
        }
    }

    if (flag === true) {
        price += 1;
    }
}

console.log(price);
//  [typescript]
const fs = require('fs')
const reader = (s: string) => (s.split("\n"))
 
function Main(input: string) {

  const [aaa,bbb] = reader(input);
  const D = bbb.split(' ');
  const [N,K] = aaa.split(' ').map(a => (parseInt(a)));

  if(K === 0) 
  {
    console.log(N);
  }
  else
  {
    for(let i= N; i < 10000 ; i++)
    {
      if(D.every( d =>(!(i.toString().includes(d)))))
      {
        console.log(i);
        break;
      }
    }
  
  }

}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))
//  [typescript]
const fs = require('fs')
const reader = (s: string) => (s.split("\n"))
 
function Main(input: string) {

  const [aaa,bbb] = reader(input);
  const D = bbb.split(' ');
  const [N,K] = aaa.split(' ').map(a => (parseInt(a)));

  for(let i= N; i < 10000 ; i++)
  {
    if(D.every( d =>(!(i.toString().includes(d)))))
    {
      console.log(i);
      break;
    }
  }

}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))
//  [typescript]
const fs = require('fs')
const reader = (s: string) => (s.split("\n"))
 
function Main(input: string) {

  const [aaa,bbb] = reader(input);
  const D = bbb.split(' ');
  const [N,K] = aaa.split(' ').map(a => (parseInt(a)));

  for(let i= N; i < 10000 ; i++)
  {
    if(!D.some( d =>(i.toString().includes(d))))
    {
      console.log(i);
      break;
    }
  }

}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))
//  [python]
k = int(input())
cnt = [0] * (k + 1)

for i in range(k, 0, -1):
    cnt[i] = (k // i) ** 3
    for j in range(i * 2, k + 1, i):
        cnt[i] -= cnt[j]

print(sum((i* cnt[i] for i in range(1, k + 1))))
//  [python]
K =int(input())
l = [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836,194157,207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813,10493367, 10611772,10813692]
print(l[K])
//  [python]
ans = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 
1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 
10493367, 10611772, 10813692]
k = int(input())
print(ans[k-1])
//  [python]
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd,numbers)

n =int(input())
c=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            c+=gcd(i,j,k)
print(c)
//  [python]
K = int(input())
total = 0

def gcd2(a,b): #互除法
  while True:
    mod = a % b
    if mod == 0:
      return b
    a = b
    b = mod

memo = {}
def gcd(a,b,c):
  a,b,c = sorted([a,b,c])
  if (a,b,c) not in memo:
    val = gcd2(gcd2(a,b), c)
    memo[(a,b,c)] = val
    return val
  return memo[(a,b,c)]

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      g = gcd(a, b, c)
#      print(a,b,c, g)
      total += g

print(total)
//  [python]
import math
k=int(input())

ans=0
for i in range(k):
  for j in range(k):
    q=math.gcd(i,j)
    for l in range(k):
      ans+=math.gcd(q,l+1)
print(ans)
//  [java]
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static long sumGCD(long[] arr){
        long max=0;
        for(int i=0;i<arr.length;i++)
            if(arr[i]>max) max=arr[i];
        long[] c=new long[(int)max+1];
        long[] d=new long[(int)max+1];
        long[] e=new long[(int)max+1];
        for(int i=0;i<arr.length;i++) c[(int)arr[i]]++;
        for(int i=1;i<=max;i++){
            for(int j=i;j<=max;j+=i) d[i]+=c[j];
        }
        for(int i=(int)max;i>=1;i--){
            e[i] = d[i]*d[i]*d[i];
            for(int j=2*i;j<=max;j+=i) e[i] -= e[j];
        }
        long sum=0;
        for(int i=1;i<=max;i++) sum+=(i*e[i]);
        return sum;
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        long[] arr=new long[n];
        for(int i=1;i<=n;i++) arr[i-1]=i;
        long ans=sumGCD(arr);
        System.out.println(ans);
    }
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		
		int total = 0;
		
		for(int a = 1; a < k+1; a++) {
			for(int b = 1; b < k+1; b++) {
				for(int c = 1; c < k+1; c++) {
					total += gcd(gcd(a, b), c);
				}
			}
		}
		System.out.println(total);
	}
	
	//ユークリッドの互除法
	static int gcd(int p, int q) {
		if(p % q == 0)	return q;	//最大公約数
		return gcd(p, p % q);		//答えが見つかるまで繰り返し
	}

}
//  [java]
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = 1, b = 1, c = 1;
        int r = 0;
        int s = 0;
        int value = 0;
        
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                a = i; b = j;
                while( (r = a % b) != 0 ) {
                    a = b;
                    b = r;
                }
                for (int k = 1; k <= n; k++) {
                    c = k;
                    while( (r = b % c) != 0 ) {
                        b = c;
                        c = r;
                    }
                    value += c;
                }   
            }
        }
        
        System.out.println(value);
    }
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int K = scan.nextInt();
		int sum = 0;

		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					sum += gcd(i, gcd(j , k));
				}
			}
		}

	}

	static int gcd(int p, int q) {
		if (p % q == 0) {
			return q;
		}
		return gcd(q, p % q);
	}
}
//  [cpp]
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

int n=3,k;

int main(){
	cin>>k;
	vl dp(k+1);
	for(int i=k;i>0;i--){
		dp[i]=Pow(k/i,n);
		for(int j=2*i;j<=k;j+=i) dp[i]=(dp[i]-dp[j]+mod)%mod;
	}
	ll res=0;
	for(int i=1;i<=k;i++) (res+=dp[i]*i)%=mod;
	cout<<res<<endl;
}
//  [cpp]
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll get(ll x, ll y) {
  ll res = 1ll;
  while(y) {
    if(y & 1) {
      res = (res * x) % MOD; 
    }
    y >>= 1;
    x = (x * x) % MOD;
  }
  return res;
}

void solve() {
  int n, k; n = 3; cin >> k;
  vector <ll> cur(k + 1);
  for(int i = 1; i <= k; i++) {
    cur[i] = get((k / i), n);
  }
  for(int i = k; i >= 1; i--) {
    for(int j = i + i; j <= k; j += i) {
      cur[i] -= cur[j];
      cur[i] %= MOD;
      if(cur[i] < 0) cur[i] += MOD;
    }
  }
  ll ans = 0;
  for(ll i = 1; i <= k; i++) {
    //cout << cur[i] << '\n';
    ans = (ans + i * cur[i]) % MOD;
  }
  cout << ans << '\n';
}

int main() {
  int t; t = 1;
  for(int cs = 1; cs <= t; cs++) {
    solve();
  }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int64_t beki(int64_t n,int64_t x){
 int64_t s,ans;
  s=(n*n)%1000000007;
  ans=(s*n)%1000000007;
  return ans;}

int main() {
int64_t n,k,a;
  a=0;
  n=3;
  cin>>k;
  vector<int64_t> ans(k);
  ans.at(k-1)=1;
  for(int64_t i=k-2;i>=0;i--){
  ans.at(i)=beki(k/(i+1),3);
    for(int64_t j=1;(i+1)*j<=k;j++){
    ans.at(i)=ans.at(i)-ans.at((i+1)*j-1);
     }
    ans.at(i)=ans.at(i)+beki(k/(i+1),3);
  }
  for(int64_t i=0;i<k;i++){a=a+(i+1)*ans.at(i);
  while(a>=1000000007){a=a-1000000007;}}
  cout<<a<<endl;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
//#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define re(s) reverse(s.begin(),s.end())
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}

int32_t main()
{
  io
int k;
cin>>k;int ans=0;
for(int i=1;i<=k;i++)
{
  for(int j=1;j<=k;j++)
  {
    for(int kk=1;kk<=k;kk++)
    {
      ans+=__gcd(i,__gcd(j,k));
    }
  }
}
cout<<ans<<endl;

}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
//#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define re(s) reverse(s.begin(),s.end())
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}

int32_t main()
{
  io
int k;
cin>>k;
for(int i=1;i<=k;i++)
{
  for(int j=1;j<=k;j++)
  {
    for(int kk=1;kk<=k;kk++)
    {
      ans+=__gcd(i,__gcd(j,k));
    }
  }
}
cout<<ans<<endl;

}
//  [cpp]
#include<iostream>
#include<stdio.h>
using namespace std;
using ll=long long;
#include<algorithm>
#include<set>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using P=pair<int,int>;
#include<cmath>


int main(){
  int k;
  cin>>k;
  int ans=0;
rep(i,k)rep(j,k)rep(n,k){
  ans+=gcd(i,gcd(j,n));
}
cout<<ans<<endl;
return 0;
}
//  [c]
#include <stdio.h>
typedef long long int lld;

int main(void) {
  int k;
  lld cnt[200], s = 0;
  scanf("%d", &k);
  for (int i = k; i > 0; i--) {
    cnt[i - 1] = (k / i);
    cnt[i - 1] *= cnt[i - 1] * cnt[i - 1];
    for (int j = i * 2; j <= k; j += i) {
      cnt[i - 1] -= cnt[j - 1];
    }
    s += i * cnt[i - 1];
  }
  printf("%lld\n", s);
}
//  [c]
int a[]={0,1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692};
main(i) {
  scanf("%d",&i);
  printf("%d",a[i]); 
}
//  [c]
#include <stdio.h>
int main()
{
	int k;
	scanf("%d",&k);
	int a[200]={1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692};
	printf("%d",a[k-1]);
	return 0;
}
//  [c]
#include<stdio.h>
int gdc(int i, int j, int k) {

	int c = 0;
	int tmp = 0;

	/*iが大きくなるように並び替える*/
	if (i < j) {

		tmp = i;
		i = j;
		j = tmp;
	}

	c = i % j;
	/*iとjの最大公約数を求める*/

	while (c > 0) {

		i = j;

		j = c;
		c = i % j;

	}



	/*i,jの最大公約数jと,kから、これらの最大公約数を求める*/

	/*kの方が大きければ入れ替える*/
	if (j < k) {

		tmp = j;
		j = k;
		k = tmp;


	}

	int d = j % k;


	while (d > 0) {

		j=k;
		k = d;
		d= j%k;

	}

	

	return k;
}


int main(void) {

	int i = 0;
	int j = 0;
	int k = 0;
	int n = 0;

	int c = 0;
	int sum = 0;



	scanf("%d", &n);

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

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

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


				c = gdc(i, j, k);

				printf("%d\n", c);
				sum = sum + c;



			}


		}

	}


	printf("答えは%d", sum);
	return 0;


}
//  [c]
#include<stdio.h>
int main() {
    int n, m, vote = 0, count = 0, a[100];
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        total = total + a[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (a[i] >= total / (4 * m))
        {
            count = count + 1;
        }

    }

    if (count >= m)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n")
    }

    return 0;
}
//  [c]
#include <stdio.h>
int main(){
  int gcd(int p, int q) {
    while (q != 0) {
      int r = p % q;
      p = q; 
      q = r;
    }
    return p;
  }
  
int main(){
    int k;
    scanf("%d", &k);
    long sum = 0;
    
    for (int a = 1; a <= k; a++)
      for (int b = 1; b <= k; b++)
        for (int c = 1; c <= k; c++)
          sum += gcd(gcd(a, b), c);
    
    printf("%ld", sum);
    return 0;
 }
//  [javascript]
"use strict";

const gcd = (a, b) => {
    if (b > a)
        return gcd(b, a);
    if (b === 0)
        return a;
    return gcd(b, (a % b));
}

const main = (input) => {
    const spi = input.split('\n');
    const k = Number(spi[0]);

    let ans = 0;
    for (let a = 1; a <= k; a++) {
        for (let b = 1; b <= k; b++) {
            let x = gcd(a, b);
            for (let c = 1; c <= k; c++) {
                ans += gcd(x, c);
            }
        }
    }

    console.log(ans);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function gcd2(a, b) {
  let m, n
  if (a >= b) {
    m = a
    n = b
  } else {
    m = b
    n = a
  }
  let bn = n
  n = m % n
  m = bn
  while(n !== 0) {
    bn = n
    n = m % n
    m = bn
  }
  return m
}
function gcd(a, b, c) {
  return gcd2(gcd2(a, b), c)
}

function main(input) {
  const K = Number(input)
  let sum = 0
  for(let i = 1; i <= K; i++) {
    for(let j = 1; j <= K; j++) {
      for(let k = 1; k <= K; k++) {
        // console.log(i, j, k, gcd(i, j, k))
        sum += gcd(i, j, k)
      }
    }
  }
  console.log(sum)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const gcd = (m, n) => {
  while (n > 0) {
    const r = m % n
    m = n
    n = r
  }
  return m
}

const Main = (input) => {
  const tmp = parseInt(input.trim())

  let result = 0

  for (let i = 1; i <= tmp; ++i) {
    for (let j = 1; j <= tmp; ++j) {
      for (let k = 1; k <= tmp; ++k) {
        result += gcd(gcd(i, j), k)
      }
    }
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
"use strict";
let m = {}
const helper = function (a, b, c) {
    let arr = [a,b,c]
    arr.sort()
    const key = arr.join("")
    if(m[key]) return m[key]
    const max = Math.max(a, b, c)
    for (let i = max; i >= 1; i--) {
        if (a % i == 0 && b % i == 0 && c % i == 0){
            m[key] = i
            return i
        } 
    }
    return 1
}

const main = arg => {
    const input = arg.trim().split("\n");
    const K = parseInt(input[0]);
    let res = 0
    for (let a = 1; a <= K; a++) {
        for (let b = 1; b <= K; b++) {
            for (let c = 1; c <= K; c++) {
                res = res + helper(a, b, c)
            }
        }
    }
    console.log(res)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
"use strict";

const helper = function (a, b, c) {
    const max = Math.max(a, b, c)
    for (let i = max; i >= 1; i--) {
        if (a % i == 0 && b % i == 0 && c % i == 0) return i
    }
    return 1
}

const main = arg => {
    const input = arg.trim().split("\n");
    const K = parseInt(input[0]);
    let res = 0
    for (let a = 1; a <= K; a++) {
        for (let b = 1; b <= K; b++) {
            for (let c = 1; c <= K; c++) {
                res = res + helper(a, b, c)
            }
        }
    }
    console.log(res)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  var input = require('fs').readFileSync('/dev/stdin', 'utf8');
  var result = 0;
  for (var a = 1; a <= input; a++) {
    for (var b = 1; b <= input; b++) {
      for (var c = 1; c <= input; c++) {
        // console.log(a + " " + b + " " + c);
        result += gcd(gcd(a, b), c);
      }
    }
  }
  console.log(result);
}


function gcd(a, b) {  
  if (b == 0) {
    return a;
  }
  return gcd(b, a%b);
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	K := nextInt()

	g := make([][]int, K+1)
	for i := range g {
		g[i] = make([]int, K+1)
		for j := range g[i] {
			g[i][j] = gcd(i, j)
		}
	}

	ans := 0
	for i := 1; i <= K; i++ {
		for j := 1; j <= K; j++ {
			for k := 1; k <= K; k++ {
				ans += g[g[i][j]][k]
			}
		}
	}
	puts(ans)
}
//  [go]
package main

import "fmt"

func main() {
	var K, sum int
	fmt.Scan(&K)
	w := make([][]int, K+1)
	for i := 0; i < len(w); i++ {
		w[i] = make([]int, K+1)
		for j := 0; j < len(w[i]); j++ {
			w[i][j] = gcd(i, j)
		}
	}
	for a := 1; a <= K; a++ {
		for b := 1; b <= K; b++ {
			for c := 1; c <= K; c++ {
				sum += w[w[a][b]][c]
			}
		}
	}
	fmt.Println(sum)
}
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
//  [go]
package main
 
import (
	"fmt"
)
 
var N, ANS int
func main() {
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			for k := 0; k < N; k++ {
				ANS += gcd(i + 1, j + 1, k + 1)
			}
		}
	}
	fmt.Println(ANS)
}

func gcd(a, b, c int)  int {
  ans := 1
  for i := 1; i <= N; i++ {
	  if a % i == 0 && b % i == 0 && c % i == 0 {
		  ans = i
	  }
  }
  return ans
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func gcd(m, n uint64) uint64 {
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	a := new(big.Int).SetUint64(m)
	b := new(big.Int).SetUint64(n)
	return z.GCD(x, y, a, b).Uint64()
}

func threeGcd(a, b, c int) int {
	array := []int{a, b, c}
	sort.Ints(array)
	gcsMin := gcd(uint64(array[0]), uint64(array[1]))
	return int(gcd(gcsMin, uint64(array[2])))
}

var sum int

func dfs(a, b, c int) {
	for x := c; 0 < x; x-- {
		for y := c; 0 < y; y-- {
			for z := c; 0 < z; z-- {
				sum += threeGcd(x, y, z)
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	k := nextInt()
	dfs(k, k, k)
	fmt.Println(sum)
}
//  [go]
package main

import (
  "fmt"
  "sort"
)

func main(){
  var N, ans int
  fmt.Scan(&N)
  
  for i := 1; i<=N; i++ {
    for j := 1; j<=N; j++ {
      for k := 1; k<=N; k++ {
        ans += gcd(i,j,k)
      }
    }
  }
  fmt.Println(ans)    
}

func gcd(a,b,c int) int {
  var R int
  val :=[]int{a, b, c}
  sort.Ints(val)
  
  A := val[0]
  B := val[1]
  C := val[2]
  

  for {
    R = abs(A - B)
    if R == 0 {
      R = A
      break
    }
    A = B
    B = R      
  }
  if B < C {
    Ctmp := C
    C = B
    B = Ctmp
  }  
  for {    
    R = abs(B-C)
    if R == 0 {
      R = B
      break
    }
    B = C
    C = R
  }
  return R
}

func abs(a int) int {
  if a < 0 {
    return -a
  }
  return a
}
//  [ruby]
mod = 10 ** 9 + 7

k,*_ = gets.split.map(&:to_i)
n = 3

a = [1] * (k+1)
b = Array.new(k+1){|i| i }

(k/2).downto(1) do |i|
  cnt = ( k/i ).pow( n, mod )
  (i*2).step(k, i){|j| cnt = ( cnt - a[j] ) % mod }
  a[i] = cnt
  b[i] = i * cnt % mod
end

ans = 0
(1..k).each do |i|
  ans += b[i]
  ans %= mod if ans >= mod
end

puts ans
//  [ruby]
puts [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692][gets.to_s.to_i]
//  [ruby]
arr = [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
p arr[gets.to_i]
//  [ruby]
k = gets.to_i
ans = 0
def gcd(i,j,k)
    x = i
    y = j
    z = k
    while y != 0
        x,y = y,x%y
    end
    while z != 0
        x,z = z,x%z
    end
    return x
end
k.times do |a|
    k.times do |b|
        k.times do |c|
            ans += gcd(a+1,b+1,c+1)
        end
    end
end
puts ans
//  [ruby]
def gcd(a, b)
  return a if b == 0
  gcd(b, a % b)
end

def gcd_3elem(a, b, c)
  gcd_2elem = gcd(a, b)
  gcd(c, gcd_2elem)
end

n = gets.chomp.to_i

s = 0
(1..n).each do |i|
  (1..n).each do |j|
    (1..n).each do |k|
      s += gcd_3elem(i, j, k)
    end
  end
end

puts s
//  [ruby]
# array = [*1..q].map { |_| gets.split.map(&:to_i) }
# n = gets.split.map(&:to_i)
# a = [*1..m].repeated_combination(n).to_a



k = gets.to_i


a = [*1..k].repeated_permutation(3).to_a

s = 0
a.each do |ary|
  s += ary[0].gcd(ary[1]).gcd(ary[2])
end

puts s
//  [rust]
use std::io::stdin;fn main(){let result:Vec<u32> = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692].to_vec();let mut st = String::new();stdin().read_line(&mut st).unwrap();let k = st.trim().parse::<usize>().unwrap();println!("{:?}",result[k-1]);}