home *** CD-ROM | disk | FTP | other *** search
/ Dos/V Magazine 2002 July 1 / VMAG130101.iso / ONLINE / monthly / calc / CLPCA511.LZH / ClipCalc / EXTFUNC / phi.cef < prev    next >
Encoding:
Text File  |  2002-08-18  |  436 b   |  27 lines

  1. #!/usr/local/bin/clip
  2. #âIâCâëü[é╠è╓Éö Euler's (totient) function
  3. #\!- <val>
  4.  
  5. if @0 < 1
  6.     :warn "èOòöè╓Éö\-é╠ê°Éöé¬0é▄é╜é═òëé╠Ælé╔é╚éΦé▄é╡é╜
  7.     return
  8. endif
  9.  
  10. :uint \10
  11.  
  12. @t = @0
  13. if @0 % 2 == 0
  14.     @t /= 2
  15.     do; @0 /= 2; until @0 % 2 == 0
  16. endif
  17. @d = 3
  18. while @0 / @d >= @d
  19.     if @0 % @d == 0
  20.         @t = @t / @d * (@d - 1)
  21.         do; @0 /= @d; until @0 % @d == 0
  22.     endif
  23.     @d += 2
  24. endwhile
  25. if @0 > 1; @t = @t / @0 * (@0 - 1); endif
  26. @t
  27.