forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOJ1142(AC).cpp
84 lines (69 loc) · 798 Bytes
/
POJ1142(AC).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <math.h>
#include <stdio.h>
#include <string.h>
long getdigitsum(long n)
{
long dsum;
long digit;
dsum = 0;
while(n > 0)
{
digit = n % 10;
dsum = dsum + digit;
n = (n - digit) / 10;
}
return dsum;
}
long getsum(long n)
{
long n0;
long sum;
long total;
long i;
n0 = n;
total = 0;
for(i = 2; i * i <= n; i++)
{
if(n % i == 0)
{
sum = getdigitsum(i);
}
while(n % i == 0)
{
total = total + sum;
n = n / i;
}
}
if(n == n0)
{
return -1;
}
if(n > 1)
{
total = total + getdigitsum(n);
}
return total;
}
int main()
{
long n;
long i;
while(1)
{
if(scanf("%ld", &n) != 1)
{
break;
}
if(n == 0)
{
break;
}
i = n + 1;
while(getsum(i) != getdigitsum(i))
{
i++;
}
printf("%ld\n", i);
}
return 0;
}