Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
41
Task/Amicable-pairs/GFA-Basic/amicable-pairs.gfa
Normal file
41
Task/Amicable-pairs/GFA-Basic/amicable-pairs.gfa
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
OPENW 1
|
||||
CLEARW 1
|
||||
'
|
||||
DIM f%(20001) ! sum of proper factors for each n
|
||||
FOR i%=1 TO 20000
|
||||
f%(i%)=@sum_proper_divisors(i%)
|
||||
NEXT i%
|
||||
' look for pairs
|
||||
FOR i%=1 TO 20000
|
||||
FOR j%=i%+1 TO 20000
|
||||
IF f%(i%)=j% AND i%=f%(j%)
|
||||
PRINT "Amicable pair ";i%;" ";j%
|
||||
ENDIF
|
||||
NEXT j%
|
||||
NEXT i%
|
||||
'
|
||||
PRINT
|
||||
PRINT "-- found all amicable pairs"
|
||||
~INP(2)
|
||||
CLOSEW 1
|
||||
'
|
||||
' Compute the sum of proper divisors of given number
|
||||
'
|
||||
FUNCTION sum_proper_divisors(n%)
|
||||
LOCAL i%,sum%,root%
|
||||
'
|
||||
IF n%>1 ! n% must be 2 or larger
|
||||
sum%=1 ! start with 1
|
||||
root%=SQR(n%) ! note that root% is an integer
|
||||
' check possible factors, up to sqrt
|
||||
FOR i%=2 TO root%
|
||||
IF n% MOD i%=0
|
||||
sum%=sum%+i% ! i% is a factor
|
||||
IF i%*i%<>n% ! check i% is not actual square root of n%
|
||||
sum%=sum%+n%/i% ! so n%/i% will also be a factor
|
||||
ENDIF
|
||||
ENDIF
|
||||
NEXT i%
|
||||
ENDIF
|
||||
RETURN sum%
|
||||
ENDFUNC
|
||||
Loading…
Add table
Add a link
Reference in a new issue