当前位置:网站首页>Leetcode perfect number simple
Leetcode perfect number simple
2022-06-13 05:49:00 【AnWenRen】
title :507 Perfect number - Simple
subject
For one Positive integer , If it and all but itself Positive factor The sum is equal , Let's call it alpha 「 Perfect number 」.
Given a Integers n, If it's a perfect number , return true, Otherwise return to false
Example 1
Input :num = 28
Output :true
explain :28 = 1 + 2 + 4 + 7 + 14
1, 2, 4, 7, and 14 yes 28 All positive factors of .
Example 2
Input :num = 6
Output :true
Example 3
Input :num = 496
Output :true
Example 4
Input :num = 8128
Output :true
Example 5
Input :num = 2
Output :false
Tips
1 <= num <= 108
Code Java
public boolean checkPerfectNumber(int num) {
if (num == 1) return false;
int sum = 1;
for (int i = 2; i < Math.sqrt(num); i++) {
if (num % i == 0)
sum += i + num / i;
}
if (sum == num)
return true;
return false;
}
边栏推荐
- How to Algorithm Evaluation Methods
- 13 cancelendevent of a flowable end event and compensationthrowing of a compensation event
- 1 Introduction to drools rule engine (usage scenarios and advantages)
- How slow is the application system on tongweb? How dead is it?
- Unity game optimization [Second Edition] learning record 6
- 10 signalstartevent and signalcatchingevent of flowable signal events
- OpenGL馬賽克(八)
- Windbos run command set
- Zero copy technology
- August 15, 2021 another week
猜你喜欢

Sentinel series hot spot current limiting

How to Algorithm Evaluation Methods

MongoDB 多字段聚合Group by

Browser screenshot method (long screenshot, node screenshot, designated area screenshot)

Concurrent programming -- source code analysis of thread pool

Ffmpeg download suffix is Video files for m3u8

16 the usertask of a flowable task includes task assignment, multi person countersignature, and dynamic forms

ffmpeg 下载后缀为.m3u8的视频文件

Why do so many people hate a-spice

Django uses redis to store sessions starting from 0
随机推荐
3. Postman easy to use
Feel the power of shardingsphere JDBC through the demo
Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio
Application virtual directory static resource configuration on tongweb
How to Algorithm Evaluation Methods
August 15, 2021 another week
Pychart professional edition's solution to SQL script error reporting
Conf/tongweb Functions of properties
顶部下滑沉浸式dialog
11 signalthrowingevent and signalboundaryevent of flowable signal event
One of PowerShell optimizations: prompt beautification
About Evaluation Metrics
NVIDIA Jetson Nano/Xavier NX 扩容教程
Leetcode- reverse vowels in string - simple
AUTOSAR actual combat tutorial pdf version
How MySQL optimizes the use of joint index ABC
Leetcode- number of words in string - simple
NVIDIA Jetson nano/xavier NX capacity expansion tutorial
Working principle of sentinel series (concept)
使用cmake交叉编译helloworld