D. Ability To Convert
time limit per test

1 second

Cmemory limit per test

256 megabytes

input

standard input

output

standard output

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·162 + 13·161 + 11·160). 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.

Input

The first line contains the integer n (2 ≤ n ≤ 109). The second line contains the integer k (0 ≤ k < 1060), 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 1018.

The number k doesn't contain leading zeros.

Output

Print the number x (0 ≤ x ≤ 1018) — the answer to the problem.

Examples
input
13
12
output
12
input
16
11311
output
475
input
20
999
output
3789
input
17
2016
output
594
Note

In the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·130 or 15 = 1·131 + 2·130.

一个星期不更博了~这场CF我没打,其实是很水的一场,不过这道题解法想到too simple,就是细节特别讨厌,会导致WA声一片。。。

题意:给你N进制与对应的数字,问转化成10进制最小是多少?

解析:一眼贪心,倒着每次尽可能取较多的数,其实证明也是很简单的(略=懒的写),不过要注意前导0问题,细节题啊~最讨厌这种带细节题的场了。DP也可以,可能DP在细节上处理的不会很烦,我这里给出贪心AC代码。

#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<utility>
#include<map>
#include<set>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<sstream>
#include<cstring>
#include<bitset>
#include<stack>
using namespace std; long long n,ans;
int l;
string k; long long powx(long long x,int y)
{
if(y==0)return 1;
long long s=powx(x,y/2);
if(y%2)return s*s*x; else return s*s;
} int main()
{
scanf("%I64d",&n);
long long t=n;
while(t>0)
{
t/=10LL;
l++;
}
cin>>k; int p=0,v=0,last=k.size()-1;
long long sum=0;
for(int i=k.size()-1;i>=0;i--)
{
long long t=sum;
sum+=powx(10,v)*(k[i]-48);
if(sum<n && v<l)v++;
else
{
int kkk=i;
if(k[i+1]=='0')
{
int ss=0;
while(k[++i]=='0')
{
ss++;
if(i==last)break;
}
i--;
}
ans+=powx(n,p)*t;
sum=k[i]-48;
v=1;
p++;
last=i;
}
}
ans+=powx(n,p)*sum;
printf("%I64d\n",ans);
return 0;
}

  

最新文章

  1. JavaScript:声明变量名的语法规则
  2. xampp 端口冲突
  3. Cookie 知识点再整理
  4. ERP联系记录管理(十七)
  5. 超级终端和SecureCRT进行Console口的连接
  6. oracle中的function 、procedure、packages、package bodies比较
  7. linux ar 命令的使用说明那个和例子[转]
  8. svn加入新的文件夹
  9. 转:apache 的mod-status
  10. 1787: [Ahoi2008]Meet 紧急集合
  11. 房上的猫:switch选择结构,与选择结构总结
  12. hdu-5786(补图最短路)
  13. CSS3_线性渐变_径向渐变----背景
  14. C# 结构(struct)的特点
  15. 阈值分割与XLD轮廓拼接——第4讲
  16. UnityShader之屏幕特效基础
  17. Linux 磁盘与文件系统(EXT2)简介
  18. Sprint2-2.0
  19. 当Shell遇上了NodeJS
  20. PowerDesigner16 生成的备注脚本,在sql server 2008 中报“对象名 &#39;sysproperties&#39; 无效”的错误的解决办法

热门文章

  1. python第一天(文件流以及控制流)简单总结
  2. LB 高可扩展性集群(负载均衡集群)
  3. Hibernate---第一个helloworld程序 (XML版本, annotation版本)
  4. UIImage创建图片的两种方式的区别
  5. (简单) POJ 3268 Silver Cow Party,Dijkstra。
  6. [iOS]使用signal让app能够在从容崩溃
  7. HUST 1351 Group
  8. Mac搭建Hadoop源码阅读环境
  9. Photoshop安装
  10. sgu194 Reactor Cooling【无源汇有上下界可行流】