Ural1014-Product of Digits
2016-11-15 21:44
302 查看
给定一个数n,要求一个最小的Q,使得Q的每一位数相乘的积为n。
不断从9到2枚举n的因子,然后除掉,这样能够使得Q的位数最少。
最后倒序输出即可。
不断从9到2枚举n的因子,然后除掉,这样能够使得Q的位数最少。
最后倒序输出即可。
#include <cstdio> #include <vector> std::vector<int> v; int main(int argc, char const *argv[]) { int n; while (scanf("%d", &n) == 1) { if (n == 0) { printf("10\n"); } else if (n < 10) { printf("%d\n", n); } else { bool ok = true; while (n != 1) { ok = false; for (int i = 9; i >= 2; i--) { if (n % i == 0) { v.push_back(i); n /= i; ok = true; break; } } if (!ok) { printf("-1\n"); break; } } if (ok) { for (int i = v.size() - 1; i >= 0; i--) { printf("%d", v[i]); } putchar('\n'); } } } return 0; }
相关文章推荐
- Ural 1014 Product of Digits 解题报告
- A - Product of Digits URAL - 1014(数位操作)
- 10 URAL 1014 Product of Digits
- Ural 1014 Product of Digits 解题报告
- URAL 1014 Product of Digits 贪心
- Ural 1014 Product of Digits NYOJ 270 数的分解 解题报告
- URAL1014 - Product of Digits - 数论
- ural 1014 the product of digits
- Ural 1014-The Product of Digits
- URAL 1014 Product of Digits
- URAL 1014 Product of Digits
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- ural 1014 Product of Digits
- URAL 1658. Sum of Digits
- [模拟]uva993 Product of digits
- UVA - 993 Product of digits 贪心
- UVa 993: Product of digits
- ural 1658. Sum of Digits
- 993 - Product of digits