303938: CF758D. Ability To Convert
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Ability To Convert
题意翻译
题目描述 亚历山大正在学习如何把十进制数字转换成其他进制,但是他不懂英文字母,所以他只是把数值按照十进制数字的方式写出来。这意味着他会用 10 代替英文字母 A。这样,他就会把十进制的 475 转换成十六进制的 11311(475=1·16^2+13·16^1+11·16^0)。亚历山大平静的生活着,直到有一天他试着把这些数字转换回十进制数字。 亚历山大记着他总是用较小的数字工作,所以他需要找到在 n 进制的基础下,用他的转换系统得出数字 k 的最小十进制数。 输入输出格式 输入格式: 第一行是一个正整数 n ( 2<=n<=10^9),第二行有一个正整数 k ,满足数字 k中包含不超过 60 个数值。第二行整数中的没每一个数字都严格小于 n。 亚历山大保证答案存在且不超过 10^18,数字 k 不含前导 0. 输出格式: 输出一个数字 x —— 问题的答案。题目描述
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter $ A $ he will write the number $ 10 $ . Thus, by converting the number $ 475 $ from decimal to hexadecimal system, he gets $ 11311 $ ( $ 475=1·16^{2}+13·16^{1}+11·16^{0} $ ). Alexander lived calmly until he tried to convert the number back to the decimal number system. Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base $ n $ he will get the number $ k $ .输入输出格式
输入格式
The first line contains the integer $ n $ ( $ 2<=n<=10^{9} $ ). The second line contains the integer $ k $ ( $ 0<=k<10^{60} $ ), it is guaranteed that the number $ k $ contains no more than $ 60 $ symbols. All digits in the second line are strictly less than $ n $ . Alexander guarantees that the answer exists and does not exceed $ 10^{18} $ . The number $ k $ doesn't contain leading zeros.
输出格式
Print the number $ x $ ( $ 0<=x<=10^{18} $ ) — the answer to the problem.
输入输出样例
输入样例 #1
13
12
输出样例 #1
12
输入样例 #2
16
11311
输出样例 #2
475
输入样例 #3
20
999
输出样例 #3
3789
输入样例 #4
17
2016
输出样例 #4
594