Hdu-1333 Smith number

Source: Internet
Author: User
# 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) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.