其他分享
首页 > 其他分享> > c求Smith数

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);
    }

标签:return,temp,int,sum,Smith,num,printf
来源: https://blog.csdn.net/weixin_46803983/article/details/120802734