Advertisement
Guest User

Burke's Sieve of Eratosthenes

a guest
Nov 2nd, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfset timestart=now()>
  2. <cfset xAry = arraynew(1)>
  3. <cfloop from='1' to="35000" index='i'>
  4. <cfset xAry[i] = true>
  5. </cfloop>
  6.  
  7. <cfset i = 2>
  8. <cfloop  condition='i le arraylen(xAry) / 2'>
  9. <cfif xAry[i] is true>
  10.           <cfset x = i>
  11.           <cfloop  condition='i*x le arraylen(xAry)' >
  12.               <cfset xAry[x*i] = false>
  13.               <cfset x++>
  14.           </cfloop>
  15.         </cfif>  
  16.   <cfset i++>
  17. </cfloop>
  18. <cfset timeend=now()>
  19.  
  20. <cfoutput>started: #timeformat(timestart, 'hh:mm.ss tt')# - ended: #timeformat(timeend, 'hh:mm.ss tt')#<br /></cfoutput>
  21.  
  22. <cfoutput>
  23.   <cfloop from='1' to='#arraylen(xAry)#' index='i'>
  24. <cfif xAry[i] is true> #numberformat(i,'999,999,999,999,999')#&nbsp;&nbsp;</cfif>
  25.   </cfloop>
  26. </cfoutput>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement