ural 1014. Product of Digits
1014. Product of Digits
Memory Limit: 64 MB
Input
Output
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相关推荐
- URAL 1014 Product of Digits
URAL_1014 基本的贪心思路是留下尽量少的项,而且这些项的字典序尽可能小.因此,要优先生成8,然后优先生成9,6,4,最后生成质数.至于为什么先生成9,再生成6,再生成4,这个可以将2.3的个数 ...
- pku,zju题目分类
哎呦喂,直接ctrl+A了.话说浙江大学的题还见过的呢.. 公告: [意见反馈][官方博客] ural pku Zju 题目分类 收藏 感谢 mugu 的提供.... Ural Problem ...
- TYUT-A专题题解(一)
TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...
- Competitive Programming 3题解
题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...
- AOAPC I: Beginning Algorithm Contests 题解
AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...
- ACM程序设计基础题解
ACM水题一 HDU1262 寻找素数对[素数] - 海岛Blog - CSDN博客 HDU4548 美素数[水题] - 海岛Blog - CSDN博客 HDU2503 a/b + c/d[水题] - ...
- ACM程序设计基础(2)题解
ACM水题二 CodeForces-1A Theatre Square[水题] - 海岛Blog - CSDN博客 AOJ0009 Prime Number[筛选法+前缀和] - 海岛Blog - C ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》
第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...
最新文章
- 使用VMware Infrastructure Client中的VMware Server 2.0.x的管理
- 老李分享:shell 监控cpu,memory,load average 1
- IIS6、7添加反向代理的步骤
- Scrapy Architecture overview--官方文档
- 操作索引库-mapping属性
- 搭建MySQL+MHA服务易错位置
- set 与 map 的第一次尝试
- cpu线程测试软件,CPU多线程测试:wPrime/国际象棋
- azure虚拟服务器,虚拟机系列
- python 网络编程 异步io_python网络编程——网络IO模型
- 【剑指offer】62、圆圈中最后剩下的数字
- 无线传感器网络与数据交换解析
- IDEA + Spring boot devtools 热部署 与 多实例启动
- 安装linux ubuntu11系统时,应该如何选择键盘布局,在ubuntu上创建新键盘布局需要哪些步骤?...
- plt.subplots_adjust(wspace=0.01, hspace=0.01)
- Android源码编译(Ubuntu 14.04)
- Mybatis Plugin 以及Druid Filer 改写SQL
- 跟上学期给我们带过课的那个夹克男一样
- OpenWRT学习笔记(1)环境部署代码下载及编译
- 划重点——线性代数考试精准扶贫