c求Smith数

c求Smith数

#include <stdio.h>


int judgePriNum(int num){
    
    //int k=(int)sqrt((double)num);
    for(int i=2;i<num+1;i++){
        if(num%i==0){
            
        return 0;
        }
    if(i>num){
        return 1;
    }
    
    }
}

int getPriSum(int num){
    int sum=0;
    while(num!=0){
        sum += num%10;
        num=num/10;
        
    }
    return sum;
}

int getComSum(int num){
    int sum=0;
    if(num>1){
        for(int i=2;i<num;i++){
            while(num%i==0){
                //printf("%d\n",i);
                sum+=getPriSum(i);
               // printf("%d\n",sum);
                num=num/i;
                //printf("%d\n",num);
            }
            
        }
        sum+=getPriSum(num);
    }
    return sum;
}

int main()
{
    
    int num;
    scanf("%d",&num);
    int temp=num+1;
    //printf("%d\n",temp);
    while(judgePriNum(temp)==1){
        temp++;
    }
    
    printf("%d ",getPriSum(temp));
    printf("%d\n",temp);
    }

上一篇:2.1深入MongoDB Shell(增删改查命令)


下一篇:前端 CSS的选择器 伪类选择器 CSS3 nth-child()