-
Notifications
You must be signed in to change notification settings - Fork 32
/
Program.cs
58 lines (51 loc) · 1.22 KB
/
Program.cs
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
using System;
using static System.Console;
namespace cs
{
class Program
{
private const int LIMIT = 440_000_000;
private int[] cache;
public Program() {
this.cache = this.GetCache();
}
private int[] GetCache()
{
int[] cache = new int[10];
cache[0] = 0;
for (int i = 1; i <= 9; ++i) {
cache[i] = (int)Math.Pow(i, i);
}
return cache;
}
private bool IsMunchausen(int number)
{
int n = number;
int total = 0;
while (n > 0)
{
int digit = n % 10;
total += cache[digit];
if (total > number) {
return false;
}
n = n / 10;
}
return total == number;
}
private void Start()
{
for (int i = 0; i < LIMIT; ++i)
{
if (IsMunchausen(i)) {
WriteLine(i);
}
}
}
public static void Main(string[] args)
{
Program p = new Program();
p.Start();
}
}
}