Smith numbers http://poj.org/problem? Id = 1142 http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 133
1 # include <cstdio> 2 int FAC [128]; 3 int find_fac (int n) {// returns the number of prime factors for N decomposition. 4 int CNT = 0; 5 For (INT I = 2; I * I <= N; I + = 2) {6 While (! (N % I) {7 N/= I; 8 FAC [CNT ++] = I; 9} 10 if (I = 2) I --; 11} 12 if (n> 1) FAC [CNT ++] = N; 13 return CNT; 14} 15 int Div (int x) {16 int res = 0; 17 while (x) {18 res + = x % 10; 19 x/= 10; 20} 21 return res; 22} 23 bool judge (int n) {24 int LF = find_fac (n); 25 if (LF = 1) return false; 26 int sum = 0; 27 for (INT I = 0; I <LF; I ++) {28 sum + = div (FAC [I]); 29} 30 if (sum = div (N) return true; 31 return false; 32} 33 int main () {34 int N; 35 while (~ Scanf ("% d", & N), n) {36 while (! Judge (++ n); 37 printf ("% d \ n", n); 38} 39 return 0; 40}View code
End