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 ;
}

Codeforces Round #549 (Div. 2)B. Nirvana的更多相关文章

  1. [题解] Codeforces Round #549 (Div. 2) B. Nirvana

    Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...

  2. Codeforces Round #549 (Div. 1)

    今天试图用typora写题解 真开心 参考 你会发现有很多都是参考的..zblzbl Codeforces Round #549 (Div. 1) 最近脑子不行啦 需要cf来缓解一下 A. The B ...

  3. B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)

    ---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...

  4. Codeforces Round #549 (Div. 2) 训练实录 (5/6)

    The Doors +0 找出输入的01数列里,0或者1先出完的的下标. Nirvana +3 输入n,求1到n的数字,哪个数逐位相乘的积最大,输出最大积. 思路是按位比较,从低到高,依次把小位换成全 ...

  5. CodeForces Round #549 Div.2

    A. The Doors 代码: #include <bits/stdc++.h> using namespace std; ; int N; , One = ; int a[maxn], ...

  6. [ Codeforces Round #549 (Div. 2)][D. The Beatles][exgcd]

    https://codeforces.com/contest/1143/problem/D D. The Beatles time limit per test 1 second memory lim ...

  7. Codeforces Round #549 (Div. 2) Solution

    传送门 A.The Doors 看懂题目就会写的题 给一个 $01$ 序列,找到最早的位置使得 $0$ 或 $1$ 已经全部出现 #include<iostream> #include&l ...

  8. Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)

    https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...

  9. Codeforces Round #549 (Div. 2) E 倍增处理按排列顺序的上一个位置

    https://codeforces.com/contest/1143/problem/E 题意 p为n的一个排列,给出有m个数字的数组a,q次询问,每次询问a数组区间[l,r]中是否存在子序列为p的 ...

随机推荐

  1. 验证码及密码加密在java中使用

    package com.huawei.filter; import java.io.IOException; import javax.servlet.Filter;import javax.serv ...

  2. java算法 蓝桥杯 摆花

    问题描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...

  3. hdu3999-The order of a Tree (二叉树的先序遍历)

    http://acm.hdu.edu.cn/showproblem.php?pid=3999 The order of a Tree Time Limit: 2000/1000 MS (Java/Ot ...

  4. XHTML的规范化

    -------------------siwuxie095                                 XHTML 简介         1.什么是 XHTML?     XHTM ...

  5. ios规格证明

    解决的方法是在Info.plist文件中添加:ITSAppUsesNonExemptEncryption 设置为NO

  6. TCP与UDP与HTTP协议

    http:是用于www浏览的一个协议.tcp:是机器之间建立连接用的到的一个协议. 1.TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层.在网络层有IP协议.ICMP协议.ARP协议.R ...

  7. 让tomcat自动定位到项目

    在servelt.xml中添加粗体部分. <Host name="localhost" appBase="webapps" unpackWARs=&quo ...

  8. spring4-2-bean配置-1-依赖注入

    配置 bean,本章节中主要介绍蓝色文字部分. 配置形式:基于 XML 文件的方式:基于注解的方式 Bean 的配置方式:通过全类名(反射).通过工厂方法(静态工厂方法 & 实例工厂方法).F ...

  9. ApexSql Log 数据库操作的后悔药

    ApexSQL Log破解版是一款功能强大的SQL数据恢复工具,支持SQL2005/2008/2012.很多时候我们存放在服务器中的SQL数据库会因黑客破坏或误操作造成数据库文件丢失的你问题,当数据库 ...

  10. tensorflow学习笔记----tensorflow在windows的安装及TensorBoard中mnist样例

    前言:                                                                                                 ...