get_string(String) :- current_input(Input),
  read_string(Input, ' \n', '', _, String).
     
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

gcdd(A,B,C,Z) :- X is gcd(A,B),Z is gcd(X,C).

solve(_,_,N,N,0).
solve(A,N,C,N,S) :- C1 is C+1,solve(A,1,C1,N,S).
solve(N,B,C,N,S) :- B1 is B+1,solve(1,B1,C,N,S).
solve(A,B,C,N,S) :- gcdd(A,B,C,Z),A1 is A+1,solve(A1,B,C,N,S1),S is S1+Z. 

main :- get_number(N),NN is N+1,solve(1,1,1,NN,S),writeln(S).