UVa 640 Self Numbers (类似素数筛)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=581


关键:

if (!vis[i]) printf("%d\n", i);
vis[d(i)] = true;

完整代码:

#include<cstdio>
const int maxn = 1000001;

bool vis[maxn];

inline int d(int n)
{
	int sum = n;
	while (n)
	{
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main()
{
	for (int i = 1; i < maxn; ++i)
	{
		if (!vis[i]) printf("%d\n", i);
		vis[d(i)] = true;
	}
	return 0;
}

你可能感兴趣的:(C++,ACM,uva)