C# - simple no square root calc


  • 0
        public bool CheckPerfectNumber(int num) {
            if (num < 2) return false;
            int sum = 1;
            for (int x = 2; x * x <= num; x++)
            {
                if (num % x == 0)
                {
                    sum += x;
                    sum += num / x;
                }
            }
            
            return sum == num;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.