pku1142.cpp

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· C++ 代码 · 共 71 行

CPP
71
字号
#include <stdio.h>
#include <math.h>
#include <memory.h>
int Add(int x)
{
	int ans;
	ans = 0;
	while (x)
	{
		ans += x % 10;
		x /= 10;
	}
	return ans;
}

int isSmith(int x)
{
	int p[11], ct[11], pn, i, ans;
	int xx = x;
	memset(ct, 0, sizeof(ct));
	pn = 0;
	for (i = 2; i * i <= x; i++)
	{
		if (x % i == 0)
		{
			p[pn] = i;
			do
			{
				x /= i;
				ct[pn]++;
			}
			while (x % i == 0);
			pn++;
		}
	}
	if (x != 1)
	{
		p[pn] = x;
		ct[pn] = 1;
		pn++;
	}
	if (pn == 1 && ct[0] == 1)
	{
		return 0;
	}
	for (i = 0, ans = 0; i < pn; i++)
	{
		ans += ct[i] * Add(p[i]);
	}
	if (ans == Add(xx))
	{
		return 1;
	}
	return 0;
}

int main()
{
	int s;
	while (scanf("%d", &s) != -1 && s != 0)
	{
		do
		{
			s++;
		}
		while (!isSmith(s));
		printf("%d\n", s);
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?