Huawei Machine Test-smith number

Source: Internet
Author: User

For a positive integer n, if its sum equals the sum of all of its factorization, then that number is called the Smith number. For example, the sum of 31257=3*3*23*151,31257 's figures is 3+1+2+5+7=18, and the sum of all its factorization figures is 3+3+2+3+1+5+1=18, so 31257 is a Smith number. Write a program to determine if the positive integer input is a smith number.


Input Description: There are multiple sets of data, each group of data has only one integer n (<100000, a row), 0 indicates the end of the input.

Output Description: For each set of data, output a Yes or no (indicates whether the number is Smith).


Input Sample:
31257
123
0
Output Sample:
Yes

No


#include <iostream> #include <vector> #include <string>using namespace std;int sum (int n)//sum of numbers {int Sum;for (sum=0;n;n/=10) Sum+=n%10;return sum;} int main () {vector<string> s;int n,i;int t1,t2,t=0;cin>>n;while (n) {int j=n;t1=sum (n); for (i=2;i<n;) {if (n%i==0) {t=t+sum (i); n=n/i;} else i++;} T2=t+sum (n), if (t1==t2&&n<j) s.push_back ("yes"), Else S.push_back ("no"); t=0;cin>>n;} for (int k=0;k<s.size (); k++) Cout<<s[k]<<endl;return 0;}


Huawei Machine Test-smith 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.