import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

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

        for(int i=1; i<=K; i++){
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(sum);
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

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

        for(int i=1; i<=K; i++){
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(sum);
    }
} Main public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

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

        for(int i=1; i<=K; i++){
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(sum);
    } main {
        
        Scanner sc = new Scanner(System.in);

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

        for(int i=1; i<=K; i++){
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int sum = 0; sum 0 for(int i=1; i<=K; i++){
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        } int i=1; int i=1; i 1 i<=K i K i++ i++ i {
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        } {
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        } for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            } int j=1; int j=1; j 1 j<=K j K j++ j++ j {
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            } {
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            } int a = i; a i int b = j; b j int kou = 0; kou 0 for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                } int x=0; int x=0; x 0 x<10 x 10 x++ x++ x {
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                } {
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                } int max = Math.max(a, b); max Math.max(a, b) Math.max Math a b int min = Math.min(a, b); min Math.min(a, b) Math.min Math a b if(max%min==0 && x==0){
                        kou = min;
                        break;
                    } max%min==0 && x==0 max%min==0 max%min max min 0 x==0 x 0 {
                        kou = min;
                        break;
                    } kou = min kou min break; a = min a min b = max % min b max % min max min if(a%b==0){
                        kou = b;
                        break;
                    } a%b==0 a%b a b 0 {
                        kou = b;
                        break;
                    } kou = b kou b break; for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                } int k=1; int k=1; k 1 k<=K k K k++ k++ k {
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                } {
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                } int c = k; c k int d = kou; d kou for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    } int x=0; int x=0; x 0 x<10 x 10 x++ x++ x {
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    } {
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    } int max = Math.max(c, d); max Math.max(c, d) Math.max Math c d int min = Math.min(c, d); min Math.min(c, d) Math.min Math c d if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        } max%min==0 && x==0 max%min==0 max%min max min 0 x==0 x 0 {
                            d = min;
                            sum += d;
                            break;
                        } d = min d min sum += d sum d break; c = min c min d = max % min d max % min max min if(c%d==0){
                            sum += d;
                            break;
                        } c%d==0 c%d c d 0 {
                            sum += d;
                            break;
                        } sum += d sum d break; System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

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

        for(int i=1; i<=K; i++){
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(sum);
    }
}