Determine the number of Smith

Subject description:

  It refers to an integer number smith decomposable satisfies the following conditions:

  Digital and equal to the number of prime factors in its entirety and on all of its bits.

  For example, 9975 is the number smith, 9975 = 3 * 5 * 5 * 7 * 19, i.e., the digital sum the digital = 9975 and Factor = 30.

  Side note: According to the definition of the smith, is not a prime number smith.
Enter multiple sets of data, the number of inputs to determine whether the number smith, if the output Yes, otherwise output No

 

Problem-solving ideas: the number n is reset input

(1) first obtains the sum of n bits each, this is very simple, not repeat

Prime factor (2) the number of required input (both divisible by n, and is a prime number), to note here is that the quality factor of the duplication, the idea detailed code.

(3) qualitative factors and calculated the number of Members. (Note! The quality factor is also seeking you and oh!)

(4) determining the sum of the respective digits and the number of quality factor and you are equal.

 

#include <the iostream> 
#include <algorithm> the using namespace STD; / * determining whether a number is a prime number * / BOOL the isPrime ( int n-) {
     IF (n-<= . 3 ) {
         return n-> . 1 ; 
    } // square root, Note that sqrt () the type of parameter type double, here to cast m, int K = ( int ) sqrt (( double ) n-);
     int I;
     for (I = 2 ; I <= K; I ++ ) {
         IF ( I ==% n- 0 ) {
             return

 



    
     to false ; 
        } 
    } 
    // if complete all cycles, and m is a prime number then 
    return  to true ; 
} 

/ * find single digits and * / 
int sumgewei ( int NUM) {
     int SumG = 0 ; // you sum of 
    the while (NUM) { 
        SumG +% NUM = 10 ; // calculated for each one and 
        NUM = NUM / 10 ; 
    } 
    return SumG; 
} 

int main () {
     int n-;
     the while (scanf_s ( " % D ", & N-)) {
         IF (the isPrime (n-)) {
             // prime number not smith 
            the printf ( " No " ); 
        } 
        the else {
             int SumG sumgewei = (n-); // you sum n- 
            int Sump = 0 ; / / quality factor sum 
            for ( int I = 2 ; I <= n-;) {
                 IF ((n-I% == 0 ) && the isPrime (I)) { 
                    Sump + = sumgewei (I); 
                    n- = n-/ I;
                } 
                The else {
                     // because To find a divisor obtained after looking prime factors of prime factors, but also starts from i = 2
                     // I ++; on only solves the problem here, also provides the above-described divisor cyclic 
                    I ++ ; 
                } 
            } 
            IF (SumG == Sump) { 
                the printf ( " Yes " ); 
            } 
            the else { 
                the printf ( " No " ); 
            } 
        } 
    } 

    System ( " PAUSE " );
     return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/syq816/p/12555849.html