Question: We can change A number A to the product of B = A. Now we can give B and determine whether A can obtain B through computation. If yes, what is it.
Question: greedy.
Let's break down B first. If the prime factor is greater than or equal to 10, it will obviously not work.
Otherwise, we can combine the factors into A, so that the product of A is equal to B.
Greedy policy: place decimals in front of them.
Note:
I. You do not have to use a prime factor. You can use it within 10.
2. High precision is required.
3.! = B
Code:
# Include <cstdio> # include <cstring> # include <algorithm> # define N 1005 using namespace std; char s [N], t [N]; int bang [15], n; bool div (int p) {int I, x = 0; memset (t, 0, sizeof (t); for (I = 1; I <= n; I ++) {x = x * 10 + s [I]; t [I] = x/p; x % = p;} if (! X) {for (x = 1; t [x] = 0; x ++); x --; n-= x; for (I = 1; I <= n; I ++) s [I] = t [I + x]; return 1;} else return 0;} int main () {// freopen ("test. in "," r ", stdin); int I; while (scanf (" % s ", s + 1), s [1]! = '-') {Memset (bang, 0, sizeof (bang); if (! S [2]) {printf ("1% c \ n", s [1]); continue;} n = strlen (s + 1); for (I = 1; I <= n; I ++) s [I] = s [I]-'0'; for (I = 9; I> 1; I --) {while (div (I) {bang [I] ++ ;}} if (n> 1) printf ("There is no such number. "); else for (I = 2; I <= 9; I ++) while (bang [I] --) printf (" % d ", I ); puts ("");} return 0 ;}
[POJ2325] Persistent Numbers greedy + high precision/low precision