您的位置:首页 > 其它

Poj 1142 Smith Numbers

2013-05-16 09:38 274 查看
暴力

1WA于因数唯一的smith数处理

2Y

#include<stdio.h>
#include<stdlib.h>
int count(int y){
	int res=0,tp=y;
	while(y){
		res+=y%10;y/=10;
		}
	return res;
	}
bool Smith(int x){
	int left=count(x);
	int i,right=0;
	int tp=x;
	for(i=2;i*i<=tp;i++){
		while(x%i==0){
			right+=count(i);
			x/=i;
			}
		}
	if(!right)return 0;
	if(x-1)right+=count(x);
	return left==right;
	}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF&&n){
		while(n++){
			if(Smith(n)){
				printf("%d\n",n);
				break;
				}
			}
		}
	return 0;
	}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: