B. Nirvana
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 11 to nn.

Input

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

Output

Print the maximum product of digits among all integers from 11 to nn.

Examples
Input

 
390
Output

 
216
Input

 
7
Output

 
7
Input

 
1000000000
Output

 
387420489
Note

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

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

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

解题思路:这道题就是给你一个n数,问你1到n之间哪个数能使各个位数相乘最大;

首先我们想到尽量将每一位变为9,然后每次都向前借一位来减。

注意当K为0时,表示前面的数字没了,所以应该返回1。

代码如下:

 #include<iostream>
#include<cmath>
using namespace std;
int n ;
int cj(int k)
{
if(k==)
return ;
if(k<)
{
return k;
} return max(cj(k/)*(k%),cj(k/-)*); }
int main()
{
cin>>n;
cout<<cj(n);
return ;
}

最新文章

  1. 常用CSS优化总结——网络性能与语法性能建议
  2. 博文写作——摘要&amp;摘要图标
  3. SWFUpload简介及中文参考手册(share)
  4. 2.Android 自定义通用的Item布局
  5. 爱默生UPS并机系统:进入与退出操作方法
  6. Atcoder CODE FESTIVAL 2016 qual C 的E题 Encyclopedia of Permutations
  7. .net 网站预编译命令
  8. 新一代 PHP 加速插件 Zend Opcache
  9. 91. Decode Ways
  10. PHP联合sqlserver2008使用的全过程 ( 原创 亲测)
  11. 数据库:JDBC编程
  12. ArcGIS Runtime SDK for Android开发之调用GP服务(异步调用)
  13. 我的 MarkDown 学习笔记
  14. Spring in Action --- 第一章 简介
  15. SSH防爆破脚本
  16. centos 7.0远程登录
  17. webpack中跨域请求proxy代理(vue与react脚手架不同设置方法)
  18. photoshop 笔记
  19. CRM项目hellokitty部分交互界面
  20. ubuntu 16.04启用root和ssh登录

热门文章

  1. nyoj27-水池数目 (求连通块数目)【dfs】
  2. 第一个MFC实例:计算圆周长和圆面积
  3. Hamming Distance二进制距离
  4. python3--多目录之间的协作的一些必备知识
  5. spring.net事件的注入
  6. 3.1.7 线程阻塞工具类:LockSupport
  7. 数据库SQL优化大总结之 百万级数据库优化方案(转)
  8. windows 安装 mysql5.7.17
  9. (1)WePHP 开启WePHP
  10. Codeigniter框架前后台部署(多目录部署)