UVa 640 - Self Numbers

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

題目網址
中文網址

Solution

直接建表。

Code

UVa 640
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<cstdio>
#define N 1000001
int main()
{
bool ans[N] = {};
for (int i = 1; i < 999999; i++)
{
int sum = i, temp = i;
while (temp)
{
sum += temp % 10;
temp /= 10;
}

if (sum < N)
ans[sum] = true;
}

for (int i = 1; i < N; i++)
if (!ans[i])
printf("%d\n", i);

return 0;
}