forked from jabbalaci/SpeedTests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.f08
43 lines (35 loc) · 801 Bytes
/
main.f08
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
program speedtest
integer, parameter :: MAX_N = 440000000
integer, dimension(10) :: cache
call calc_cache(cache)
do i = 0, MAX_N
if (is_munchausen(cache, i)) then
print '(i0)', i
end if
end do
contains
subroutine calc_cache(cache)
integer, dimension(10), intent(out) :: cache
cache(1) = 0
do i = 1, 9
cache(i+1) = i**i
end do
end subroutine
logical function is_munchausen(cache, num)
integer, dimension(10), intent(in) :: cache
integer, intent(in) :: num
integer :: n, total, digit
n = num
total = 0
do while (n > 0)
digit = mod(n, 10)
total = total + cache(digit+1)
if (total > num) then
is_munchausen = .false.
return
end if
n = n / 10
end do
is_munchausen = total == num
end function
end program speedtest