当前位置:网站首页>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;
}
边栏推荐
- Application virtual directory static resource configuration on tongweb
- 【自动化测试】Cypress手册
- 软件测试——接口常见问题汇总
- Etcd fast cluster building
- 9. Errorstartevent and errorboundaryevent of error events
- MongoDB 多字段聚合Group by
- Set the correct width and height of the custom dialog
- Sentinel series integrates Nacos and realizes dynamic flow control
- Current limiting and fusing of gateway gateway in Spirng cloud
- Information collection for network security (2)
猜你喜欢
How to Algorithm Evaluation Methods
OpenGL Mosaic (8)
MySQL fuzzy query and sorting by matching degree
NVIDIA Jetson nano/xavier NX capacity expansion tutorial
MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
Browser screenshot method (long screenshot, node screenshot, designated area screenshot)
Source code analysis of ArrayList
ArrayList loop removes the pit encountered
Building a stand-alone version of Nacos series
Sentinel series integrates Nacos and realizes dynamic flow control
随机推荐
软件测试——接口常见问题汇总
Leetcode- distribute cookies - simple
Function and application scenario of field setaccessible() method
为什么那么多人讨厌A-Spice
= = relation between int and integer
Summary of the 11th week of sophomore year
零拷贝技术
The problem of distinguishing and sharing sessions for multiple applications in tongweb
Class conflicts caused by tongweb Enterprise Edition and embedded Edition
Explanation of service registration and discovery API of Nacos series
Misunderstanding of tongweb due to ease of use
OpenGL馬賽克(八)
Top slide immersive dialog
2021.9.29学习日志-Restful架构
About Evaluation Metrics
3. Postman easy to use
Pychart encountered time zone problem when connecting to MySQL timezone
ffmpeg 下载后缀为.m3u8的视频文件
Find out the missing numbers from the natural numbers arranged in order from 0 to 100, and the solution provides
Basic application of sentinel series