abhas Active member
| Subject: Perfect number generator java program Fri Dec 11, 2009 3:55 pm | |
| In mathematics, a perfect number is a positive integer that is the sum of its proper positive divisors, that is, the sum of the positive divisors excluding the number itself. Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself), or σ(n) = 2n.
The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6.
public static int perfect(int n){ double m=n; int perfect; perfect=Math.pow(2,(m-1))*(Math.pow(2,m)-1); return perfect; } |
|