Given n, which requires you to output all the n-digits that conform to the rule
As a rule, this n-bit number is multiplied by two n/2 digits, and satisfies
1. This n-digit number is even
2. All the numbers on these two n/2 digits just make up this n-digit number.
3. Two N/2 digits cannot be a multiple of 10
Problem-solving ideas: Because the input only 4,6,8, so first preprocessing, violent enumeration 4,6,8 situation, and then hit the table
#include <cstdio>#include <set>#include <cmath>using namespace STD;#define MAXN Set<int>ANS[MAXN];intVIS[MAXN];voidInitintN) {intStart =POW(Ten, N-1);intEnd =POW(Ten, n);intMIN =POW(Ten,2N1);intMAX =POW(Ten,2*N); for(inti = start; I < end; i++) for(intj = i; J < End; J + +) {ifITen==0&& J%Ten==0)Continue;intt = i * j;if(t%2|| T < MIN | | T >= MAX)Continue;intx = i, y = j; for(inti =0; I <Ten; i++) Vis[i] =0; while(x) {vis[x%Ten]++; x = x/Ten; } while(y) {vis[y%Ten]++; y = y/Ten; }BOOLFlag =true;inttt while(t) {tt = t%Ten;if(Vis[tt] = =0) {flag =false; Break; } vis[tt]--; T/=Ten; }if(flag) ans[n*2].insert (I*J); }}intMain () {intN Init2); Init3); Init4); while(scanf("%d", &n) = =1) { for( Set<int>:: Iterator it = Ans[n].begin (); It! = Ans[n].end (); it++)printf("%d\n", *it);printf("\ n"); }return 0;}
UVA-10396 Vampire Numbers violence + Play Watch