In number theory, a weird number is a natural number that is abundant but not semiperfect (and therefore not perfect either).

In other words, the sum of the proper divisors of the number (divisors including 1 but not itself) is greater than the number itself (the number is abundant), but no subset of those divisors sums to the number itself (the number is not semiperfect).

For example:

 12 is not a weird number.
 It is abundant; its proper divisors 1, 2, 3, 4, 6 sum to 16 (which is > 12),
 but it is semiperfect, e.g.:     6 + 4 + 2 == 12.
 70 is a weird number.
 It is abundant; its proper divisors 1, 2, 5, 7, 10, 14, 35 sum to 74 (which is > 70),
 and there is no subset of proper divisors that sum to 70.


Task

Find and display, here on this page, the first 25 weird numbers.



Related tasks

 Abundant, deficient and perfect number classifications
 Proper divisors


See also

 OEIS: A006037 weird numbers
 Wikipedia: weird number
 MathWorld: weird number


 
Function GetFactors(n As Long,r() As Long) As Long
      Redim r(0)
      r(0)=1
      Dim As Long count,acc
      For z As Long=2 To n\2 
            If n Mod z=0 Then 
                  count+=1:redim preserve r(0 to count)
                  r(count)=z
                  acc+=z
            End If
      Next z
      Return 1+acc
End Function
 
sub sumcombinations(arr() As Long,n As Long,r As Long,index As Long,_data() As Long,i As Long,Byref ans As Long,ref As Long) 
      Dim As Long acc
      If index=r Then
            For j As Long=0 To r-1
                  acc+=_data(j)
                  If acc=ref Then ans=1:Return
                  If acc>ref then return
            Next j
            Return
      End If
      If i>=n Or ans<>0 Then Return  
      _data(index) = arr(i) 
      sumcombinations(arr(),n,r,index + 1,_data(),i+1,ans,ref)
      sumcombinations(arr(),n,r,index,_data(),i+1,ans,ref)
End sub
 
Function IsWeird(u() As Long,num As Long) As Long
      Redim As Long d()
      Dim As Long ans
      For r As Long=2 To Ubound(u)
            Redim d(r)
            ans=0
            sumcombinations(u(),Ubound(u)+1,r,0,d(),0,ans,num)
            If ans =1 Then  Return 0
      Next r
      Return 1
End Function
 
Redim As Long u()
Dim As Long SumFactors,number=2,count
Do
      number+=2
      SumFactors=GetFactors(number,u())
      If SumFactors>number Then
            If IsWeird(u(),number) Then Print number;" ";:count+=1
      End If
Loop Until count=25
Print
Print "first 25 done"
Sleep
 