Welcome

首页 / 软件开发 / 数据结构与算法 / UVa 640 Self Numbers:类似素数筛

UVa 640 Self Numbers:类似素数筛2014-07-07 synapse7 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=581

关键:

01.if (!vis[i]) printf("%d
", i);02.vis[d(i)] = true;
完整代码:

01.#include<cstdio>02.const int maxn = 1000001;03.04.bool vis[maxn];05.06.inline int d(int n)07.{08.int sum = n;09.while (n)10.{11.sum += n % 10;12.n /= 10;13.}14.return sum;15.}16.17.int main()18.{19.for (int i = 1; i < maxn; ++i)20.{21.if (!vis[i]) printf("%d
", i);22.vis[d(i)] = true;23.}24.return 0;25.}