I am doing Project Euler 29 in Fortran. I am having a problem when the numbers get too big (I believe that is the case as the numbers turn negative when I print them), although I am using int64 from iso_fortran_env. This is my code (ignore the line numbers on the left):
1 PROGRAM MAIN
1 USE ISO_FORTRAN_ENV
2 IMPLICIT NONE
3 REAL :: START, FINISH
4 INTEGER :: COUNTER
5 INTEGER(KIND=INT64) :: A_LARGEINT(100000) !ARRAY THAT
6 !CONTAINS THE NUMBERS
7 INTEGER :: I,K,POS
8 INTEGER(KIND=INT64) :: NUM_LARGEINT
9 CALL CPU_TIME(START)
10 COUNTER=0
11 POS=1
12 DO I=2,100
13 DO K=2,100
14 NUM_LARGEINT = I**K
15 !NUM_LARGEINT = HUGE(NUM)
16 PRINT *,NUM_LARGEINT
17 IF (ANY(A_LARGEINT==NUM_LARGEINT)) THEN
18 ELSE
19 COUNTER = COUNTER + 1
20 A_LARGEINT(POS) = NUM_LARGEINT
21 POS = POS + 1
22 ENDIF
23 ENDDO
24 ENDDO
25 PRINT*, A_LARGEINT, COUNTER
26 CALL CPU_TIME(FINISH)
27 PRINT*, "TIME TAKEN: ", FINISH-START
28 END PROGRAM MAIN
Any suggestions why this int64 type doesn't work? Or if there is any way to deal with even larger integers?
Many thanks in advance