---恢复内容开始---

Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.

Help Kurt find the maximum possible product of digits among all integers from 1 to n.

Input

The only input line contains the integer nn (1≤n≤2⋅109).

Output

Print the maximum product of digits among all integers from 1 to n.

Examples
Input

Copy
390
Output

Copy
216
Input

Copy
7
Output

Copy
7
Input

Copy
1000000000
Output

Copy
387420489
Note

In the first example the maximum product is achieved for 389389 (the product of digits is 3⋅8⋅9=216).

In the second example the maximum product is achieved for 77 (the product of digits is 7).

In the third example the maximum product is achieved for 99999999 (the product of digits is 99=38742048999).

题意:给出n,找出不大于n的一个数,试其乘积最大。

思路:对于一个位置上的数,①可以保持不变,②可以使其变成9,前置位-1.

这样我们可以递归枚举。

 #include<bits/stdc++.h>
using namespace std; int n; int cal(int n)
{
if(n == )return ;
else if(n < )return n;
else
{
return max(cal(n/)*(n%),cal(n/-)*);
}
} int main()
{
scanf("%d",&n);
printf("%d\n",cal(n));
}

---恢复内容结束---

最新文章

  1. window 运行指令(1)
  2. maven No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
  3. C#中使用DLL文件
  4. GUI编程笔记(java)09:GUI控制文本框只能输入数字字符案例
  5. 版本控制-git的使用
  6. java实例变量及方法调用顺序
  7. perconaXTRADB Cluster在Redhat Linux上的安装
  8. boost库之geometry
  9. Python Fabric远程自动部署简介
  10. 3. VIM 系列 - 遇见你的第一个插件
  11. Navicat 连接VMware中Ubuntu 下的mysql5.7遇到的坑
  12. bat执行python脚本,执行多条命令
  13. .net core 2.0 Unable to convert MySQL date/time to System.DateTime
  14. 《JavaScript Dom 编程艺术》读书笔记-第6章
  15. 51nod 1092(lcs)回文字符串
  16. 【Python】进程间共享实例
  17. 《算法》第六章部分程序 part 2
  18. 【Java基础】JAVA不可变类(immutable)机制与String的不可变性
  19. zz VS2010配色方案
  20. C#中调用Dll动态链接库

热门文章

  1. 【CF1132G】Greedy Subsequences(线段树)
  2. java 11 不可修改集合API
  3. ASP.NET概念
  4. ubuntu:基本操作;
  5. 10分钟快速搞定pandas
  6. consul kv使用介绍
  7. hotplug/mdev机制
  8. Pandas系列(五)-分类数据处理
  9. java.util.ConcurrentModificationException异常原因及解决方法
  10. HTTP中application/x-www-form-urlencoded字符说明