[LeetCode]#507. Perfect Number

Input: 28
Output: True
Explanation: 28 = 1 + 2 + 4 + 7 + 14
import math
class Solution:
def checkPerfectNumber(self, num):
if num<=1:
return False
scale=int(math.sqrt(num))
ans=1

for i in range(2,scale+1):
if num % i==0:
ans+=i+num/i
return num == ans

--

--

--

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Big O Notation

A/B Testing with Google Optimize and Redux

You can now test Alpha builds of Feren OS on an Ubuntu 20.04 LTS Base

PDF Download& Exploring Arduino: Tools and Techniques for Engineering Wizardry Read #book #ePub

Portfolio Project #3: Ruby on Rails — Artphilia

An Intro to Your ESP8266

CONFIGURING HADOOP AND STARTING CLUSTER SERVICES USING ANSIBLE PLAYBOOK!

Do You Know Immutable Class in Java? Why String is Immutable?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

Leetcode — Merge Sorted Array

Arrays Data Structures Explained

LeetCode Patterns Adventure 12 — Palindrome Linked List

ARRAYS AND STRINGS DATA STRUCTURES.