Ural 1014 Product of Digits NYOJ 270 数的分解 解题报告
2011-12-28 23:08
260 查看
题意:
是找到一个最小的正整数Q,使Q的各位数的乘积等于N。
思路:
从9到2取余。
是找到一个最小的正整数Q,使Q的各位数的乘积等于N。
思路:
从9到2取余。
#include <iostream> #include <algorithm> using namespace std; bool fun(int x,int *ops,int &num) { if(x==1) return 1; for(int i=9;i>=2;i--) { if(x%i==0) { ops[num]=i; //ops存储分解后的数集合 num++; return fun(x/i,ops,num); } } return 0; } int main() { int n; while(cin>>n) {if(n==0) cout<<10<<endl; else if(n<=9) cout<<n<<endl; else { int ops[11]; int num=0; if(fun(n,ops,num)) { sort(ops,ops+num); for(int k=0;k<num;k++) cout<<ops[k]; cout<<endl; } else cout<<-1<<endl; } } return 0; }
相关文章推荐
- Ural 1014 Product of Digits 解题报告
- Ural 1014 Product of Digits 解题报告
- 10 URAL 1014 Product of Digits
- A - Product of Digits URAL - 1014(数位操作)
- URAL 1014 Product of Digits 贪心
- URAL1014 - Product of Digits - 数论
- Ural1014-Product of Digits
- 【解题报告】 NYOJ 541 最强DE 战斗力 -- 数论
- URAL 1654 Cipher Message 解题报告
- URAL 1014 Product of Digits
- URAL 1014 Product of Digits
- URAL 1181 Cutting a Painted Polygon(解题报告)
- URAL 1010 Discrete Function(解题报告)
- nyoj 题目270 数的分解
- 【ACM菜逼解题报告】矩形嵌套(NYOJ16)
- Ural 1091 Tmutarakan Exams 解题报告(容斥原理)
- Ural 1114. Boxes 解题报告(组合数计算)
- uva 993 Product of digits (分解因子)
- URAL1785解题报告
- ural 1014 the product of digits