If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > The Perfect Number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 07-18-09, 22:26
DB2Plus DB2Plus is offline
Registered User
 
Join Date: Jul 2009
Posts: 150
The common solution on integer shown by author:

Quote:
with perfect (number, divider, sum_divider, show_d, limit) as ( select 2, 1, 1, varchar('1 ', 10000), 500
from sysibm.sysdummy1
union all
select number,
divider + 1,
case
when number = (divider + 1) * int(number / (divider + 1))
then sum_divider + (divider + 1)
else sum_divider
end,
case
when number = (divider + 1) * int(number / (divider + 1))
then show_d || ' + ' || varchar(divider + 1)
else show_d
end
,
limit
from perfect
where divider + 1 <= number / 2
and number <= limit
and divider + 1 <= limit / 2
and sum_divider <= number

union all
select number + 2, 1, 1, '1 ', limit
from perfect
where
( divider + 1 > number / 2
and number + 2 <= limit )
or
( divider + 1 <= number / 2
and number + 2 <= limit
and divider <= limit / 2
and sum_divider > number )
)
select number "perfect number", show_d
from perfect p1
where
p1.number =
(select max(p2.sum_divider) from perfect p2
where p2.number = p1.number)
and
p1.divider =
(select max(p2.divider) from perfect p2
where p2.number = p1.number)
;
But it's take too long and needs some optimizitation.

Kara Sw., NY
Reply With Quote
  #17 (permalink)  
Old 07-21-09, 12:51
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Why 1 is not a perfect number ?

1 = Sum(1). It could be only one known odd perfect number.


Lenny (Citigroup)
Reply With Quote
  #18 (permalink)  
Old 07-21-09, 16:34
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by Lenny77
Why 1 is not a perfect number ?
1 = Sum(1).
It could be only one known odd perfect number.
With that definition, 1 would be the only perfect number, since it's the only positive integer for which the sum of its divisors equals that number.
Since all other numbers n have 1 and itself as two divisors (at least), the sum of their divisors is always at least n+1.
(Actually, for a prime number n, it will be exactly n+1; for all other numbers, the sum will be strictly larger than n+1.)

For a perfect number n, Sum(divisors of n) = 2n.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #19 (permalink)  
Old 07-21-09, 18:24
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
How I know the problem with the odd perfect numbers did not solve yet.
Even nobody knows about exists or not exists such numbers.

It could be one of them.


Lenny
Reply With Quote
  #20 (permalink)  
Old 09-29-09, 17:00
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Lightbulb New way to get small perfect numbers

The new way to get small perfect numbers:

Code:
with 
Input(Lim) as
(select int(1e3) from sysibm.sysdummy1
)
,
Perfect_No (perf_cand, fact_sum, fact, lim) as
(select  int(4), int(1), int(1), lim 
   from Input  
union all
select perf_cand, fact_sum, fact + 1, lim 
  from Perfect_No 
 where mod(perf_cand, fact + 1) > 0
   and fact + 1   <= sqrt(perf_cand) 
   and fact_sum   <=  perf_cand
union all
select perf_cand, fact_sum + (fact + 1) + (perf_cand / (fact + 1)), fact + 1, lim
  from Perfect_No 
 where mod(perf_cand, fact + 1) = 0
   and fact + 1 <= sqrt(perf_cand) 
   and fact_sum <=  perf_cand
union all
select perf_cand + 1, 1, 1, lim 
  from Perfect_No 
 where (fact + 1 > sqrt(perf_cand) or fact_sum > perf_cand)
   and perf_cand + 1 <= lim   
) 
, 
Just_A_Perfect (perfect_number) as
(
select   distinct perf_cand 
  from   Perfect_No  p1
   where perf_cand = (select max(fact_sum) 
                       from Perfect_No p2 where p1.perf_cand = p2.perf_cand )
) 
select perfect_number from Just_A_Perfect
As Result:

Quote:
PERFECT_NUMBER
6
28
496

Lenny
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On