回复 20楼 pcbaichi
行。谢谢!
#include <stdio.h> int totalNum(int n) //求自然数n各位数字和 { int total_num = 0; while(n%10) { total_num+=n%10; n/=10; } //得出n各位数字和 return total_num; } int isPrime(int n) { int i; if (n==2) return 1; else for(i=2; i!=n; ++i) { if(n%2 == 0) break; } return (i==n)?1:0; } int isSmith(int n) //是否是smith数 { int i; int total_num = 0; int t = n; //临时变量 for(i = 2; i!=n; ++i) { if (isPrime(i)) //如果i为质数 { while(!(t%i)) { total_num+=totalNum(i); t/=i; } } } return (total_num == totalNum(n))?1:0; } int main() { int t; while(scanf("%d",&t) && t) { puts(isSmith(t)?"yes":"no"); } return 0; }