题意:给你一个数字y,生成另外一个最小的数字x,使得x里面的每一位相乘等于y
解题思路:直接贪心就是,x里面的每一位都小于等于9
#include <string> #include<iostream> #include<map> #include<memory.h> #include<vector> #include<algorithm> #include<queue> #include<vector> #include<stack> #include<math.h> #include<iomanip> #include<bitset> #include"math.h" namespace cc { using std::cout; using std::endl; using std::cin; using std::map; using std::vector; using std::string; using std::sort; using std::priority_queue; using std::greater; using std::vector; using std::swap; using std::stack; using std::queue; using std::bitset; constexpr int N = 100; int a[N] = {0}; int l = 0; void solve() { int n; cin >> n; long long Q; while (n--) { cin >> Q; memset(a,-1,sizeof(a)); l = 0; if (Q == 1) { cout << 1 << endl; continue; } while (Q!=1) { int cur = 0; for (int i = 9;i >= 2;i--) { if (Q >=i && Q%i==0) { cur = i; break; } } if (cur == 0) { l = -1; break; } a[l++] = cur; Q = Q / cur; } if (l == -1) { cout << -1 << endl; } else { for (int i=l-1;i>=0;i--) { cout << a[i]; } cout << endl; } } } }; int main() { #ifndef ONLINE_JUDGE freopen("d://1.text", "r", stdin); #endif // !ONLINE_JUDGE cc::solve(); return 0; }