# Include <iostream> using namespace STD; const int maxn = 1e4 + 100; int plist [maxn]; int pcount = 0; // determine whether a number is a prime number bool prime (int n) {int I; If (n! = 2 &&! (N % 2) | (n! = 3 &&! (N % 3) | (n! = 5 &&! (N % 5) | (n! = 7 &&! (N % 7) return 0; for (I = 0; plist [I] * plist [I] <= N; I ++) if (! (N % plist [I]) return 0; return n> 1;} void initprime () {int I; for (plist [pcount ++] = 2, I = 3; I <50000; I ++) if (prime (I) plist [pcount ++] = I;} int resolve_number (INT N) {int ret = 0; while (n! = 0) {RET + = n % 10; N/= 10;} return ret;} int sum_factors (int n) {int ret = 0; int I; for (INT I = 2; I * I <= N; I ++) if (N % I = 0) {// cout <"----- I =" <I <"n =" <n <Endl; N/= I, RET + = resolve_number (I ); while (N % I = 0) {n/= I, RET + = resolve_number (I );} // cout <"----- I =" <I <"n =" <n <Endl ;}} if (n> 1) RET + = resolve_number (n); return ret;} int main () {// cout <resolve_number (4937775) <E NDL; // cout <sum_factors (4937775) <Endl; initprime (); int N; while (CIN> N & N) {While (N ++) {If (! Prime (n) & sum_factors (n) = resolve_number (N) {cout <n <Endl; break ;}} return 0 ;}
required knowledge: filtering prime numbers + printing prime numbers using a prime number table + finding a factor and (similar to finding a pulled number)