home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / cpmug / cpmug004.ark / AMAZE < prev    next >
Encoding:
Text File  |  1984-04-29  |  1.4 KB  |  59 lines

  1. `
  2. The prime factors of n!
  3.  
  4.     n! = p(1)**j(1) p(2)**j(2) p(3)**j(3) ...
  5.  
  6. can be calculated by the following algorithm, where "/" is
  7. an integer divide with the remainder discarded.  To find the
  8. power j of some prime p in n!, calculate the sum
  9.  
  10.     j = n/p + n/p**2 + n/p**3 + ...
  11.  
  12. using the recursion relation
  13.  
  14.     n/p**(i+1) = (n/p**i)/p
  15.  
  16. (In the ACT program, "a" is the current term in the j sum.)
  17. `
  18.  
  19. @{ns|prime factors of n!|{
  20.     @{ns|n|@{rs|Type an integer less than 600.   }}
  21.     @{ge|@@{n}|50|{@{ps|This may take a minute or two.|}}}
  22.     @{dd|answer}
  23.     @{cr|primes}@{prime loop}
  24.     @{ps||@@{n}! =@@{answer}||}
  25.     @{prime factors of n!}
  26. }}
  27.  
  28. @{ns|prime loop|{
  29.     @{ns|p|@@{in|primes| }}
  30.     @{ns|a|@@{dv|@@{n}|@@{p}}}
  31.     @{ge|@@{a}|1|{
  32.         @{ns|j|0}@{calc j}
  33.         @{ns|answer|@@{answer} @@{p}@@{ge|@@{j}|2|**@@{j}}}
  34.         @{prime loop}
  35.     }}
  36. }}
  37.  
  38. @{ns|calc j|{
  39.     @{ns|j|@@{ad|@@{j}|@@{a}}}
  40.     @{ns|a|@@{dv|@@{a}|@@{p}}}
  41.     @{ge|@@{a}|1|{
  42.         @{calc j}
  43.     }}
  44. }}
  45.  
  46. @{ns|primes|{
  47. 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
  48.  73 79 83 89 97 101 103 107 109 113 127 131 127 131 137 139 149
  49.  151 157 163 167 173 179 181 191 193 197 199 211
  50.  223 227 229 233 239 241 251 257 263 269 271
  51.  277 281 283 293 307 311 313 317 331 337 347 349
  52.  353 359 367 373 379 383 389 397 401 409 419
  53.  421 431 433 439 443 449 457 461 463 467 479 487
  54.  491 499 503 509 521 523 541 547 557 563 569 571 577 587 593
  55.  599
  56.  }}
  57.  
  58. @{prime factors of n!}
  59.