SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Prime Number Factorization
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 08/01/2009 :  20:40:12  Show Profile  Visit SwePeso's Homepage  Reply with Quote
This piece of code depends on you having a present table with prime numbers ranging from 2 to 3037000493.
DECLARE	@Number BIGINT

SET	@Number = 2020208534430421

SELECT	Prime AS Number,
	CAST(1 AS TINYINT) AS Items
INTO	#Temp
FROM	Primes
WHERE	Prime <= SQRT(@Number)
	AND @Number % Prime = 0

WHILE @@ROWCOUNT > 0
	UPDATE	#Temp
	SET	Items = Items + 1,
		@Number = @Number / Number
	WHERE	@Number % Number = 0

SELECT	Number,
	Items
FROM	#Temp

UNION ALL

SELECT	@Number,
	1
WHERE	@Number > 1

DROP TABLE	#Temp



N 56°04'39.26"
E 12°55'05.63"

Edited by - SwePeso on 08/01/2009 20:55:03
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000