1014. Product of Digits

Time Limit: 1.0 second
Memory Limit: 64 MB
Your task is to find the minimal positive integer number Q so that the product of digits of Q is exactly equal to N.

Input

The input contains the single integer number N (0 ≤ N ≤ 109).

Output

Your program should print to the output the only number Q. If such a number does not exist print −1.

Sample

input output
10
25
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;int main(){long long n;cin >> n;if(n == 0){cout<<10<<endl;return 0;}if(n == 1){cout<<1<<endl;return 0;}vector<int> product;bool flag = false;while(n!=1){int i;for(i = 9;i>1; i -- ){if(n%i == 0) {product.push_back(i);n /=i; ;break;}}if( i== 1) {if(n < 10) product.push_back(n);else flag = true;break;}}if(flag) {cout<<-1<<endl;return 0;}long long ans = 0;for(int i = product.size()-1 ; i >= 0 ; i-- ){ans = ans*10+product[i];}cout<<ans<<endl;return 0;
}

转载于:https://www.cnblogs.com/xiongqiangcs/archive/2013/04/23/3037151.html

ural 1014. Product of Digits相关推荐

  1. URAL 1014 Product of Digits

    URAL_1014 基本的贪心思路是留下尽量少的项,而且这些项的字典序尽可能小.因此,要优先生成8,然后优先生成9,6,4,最后生成质数.至于为什么先生成9,再生成6,再生成4,这个可以将2.3的个数 ...

  2. pku,zju题目分类

    哎呦喂,直接ctrl+A了.话说浙江大学的题还见过的呢.. 公告: [意见反馈][官方博客]   ural pku Zju 题目分类 收藏   感谢 mugu 的提供.... Ural Problem ...

  3. TYUT-A专题题解(一)

    TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...

  4. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  5. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  6. ACM程序设计基础题解

    ACM水题一 HDU1262 寻找素数对[素数] - 海岛Blog - CSDN博客 HDU4548 美素数[水题] - 海岛Blog - CSDN博客 HDU2503 a/b + c/d[水题] - ...

  7. ACM程序设计基础(2)题解

    ACM水题二 CodeForces-1A Theatre Square[水题] - 海岛Blog - CSDN博客 AOJ0009 Prime Number[筛选法+前缀和] - 海岛Blog - C ...

  8. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  9. ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》

    第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...

最新文章

  1. 使用VMware Infrastructure Client中的VMware Server 2.0.x的管理
  2. 老李分享:shell 监控cpu,memory,load average 1
  3. IIS6、7添加反向代理的步骤
  4. Scrapy Architecture overview--官方文档
  5. 操作索引库-mapping属性
  6. 搭建MySQL+MHA服务易错位置
  7. set 与 map 的第一次尝试
  8. cpu线程测试软件,CPU多线程测试:wPrime/国际象棋
  9. azure虚拟服务器,虚拟机系列
  10. python 网络编程 异步io_python网络编程——网络IO模型
  11. 【剑指offer】62、圆圈中最后剩下的数字
  12. 无线传感器网络与数据交换解析
  13. IDEA + Spring boot devtools 热部署 与 多实例启动
  14. 安装linux ubuntu11系统时,应该如何选择键盘布局,在ubuntu上创建新键盘布局需要哪些步骤?...
  15. plt.subplots_adjust(wspace=0.01, hspace=0.01)
  16. Android源码编译(Ubuntu 14.04)
  17. Mybatis Plugin 以及Druid Filer 改写SQL
  18. 跟上学期给我们带过课的那个夹克男一样
  19. OpenWRT学习笔记(1)环境部署代码下载及编译
  20. 划重点——线性代数考试精准扶贫

热门文章

  1. str字符串 encoding( ) 方法
  2. 【python】 web开发入门
  3. BZOJ 3223: Tyvj 1729 文艺平衡树(splay)
  4. 拉曼软件在win8上运行出错问题
  5. Android数据存储之SQLite的操作
  6. Duo Labs:五大厂商的笔记本预装软件存在重大安全隐患
  7. 公众号自定义图文消息推送(2)
  8. Python学习笔记(六)
  9. POS DES MAC 算法
  10. f_bfree和f_bavail的区别