Gets if a number is an abundant number. - Java java.lang

Java examples for java.lang:Math Number

Description

Gets if a number is an abundant number.

Demo Code


//package com.java2s;

public class Main {
    /**/*from w w w  .  j av a  2 s .  co  m*/
     * Gets if a number is an abundant number.
     * @param num Number to test
     * @return If the number is abundant
     */
    public static boolean isAbundantNumber(long num) {
        long sum = 0;
        for (long i = 1; i <= Math.sqrt(num); i++) {
            if (num % i == 0) {
                sum += (i == 1 || i * i == num) ? i : i + (num / i);
            }
        }
        return sum > num;
    }
}

Related Tutorials