package com.thinker.bishi.huawei;

import java.util.Scanner;

/**
 * @author lzh
 * @apiNote 华为笔试第二道题，题目记得不太清楚
 */
public class HexChange {
    private static StringBuilder result = new StringBuilder();
    private static void hexChange(int num,int hex){
        if(hex == 0) return ;
        int residue = num % hex;
        num = num/hex;
        result.append(residue);
        if(num == 0) return;
        hexChange(num,hex);
    }

    private static int getResult(int num,int hex){
        hexChange(num,hex);
        StringBuilder tmp = new StringBuilder();
        for(int i=0;i<result.length();i++){
            tmp.append(result.charAt(result.length()-1-i));
        }
        result = new StringBuilder();
        return Integer.parseInt(tmp.toString());
    }
    private static void result(int num){
        if(num > 0 && num <= 10){
            Integer sum = 0;
            int hex = 2;
            while (hex<=num){
                sum += getResult(num,hex);
                hex ++;
            }
            System.out.println(sum);
        }else {
            System.out.println("error");
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        result(num);
    }
}
