-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path507.java
More file actions
44 lines (39 loc) · 972 Bytes
/
507.java
File metadata and controls
44 lines (39 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public boolean checkPerfectNumber(int num) {
int primes[]= new int[]{2,3,5,7,13,19,31};
for (int prime: primes) {
if(merseenePrimes(prime) == num)
return true;
}
return false;
}
public int merseenePrimes(int p){
return (1 << (p -1)) * ((1 << p) - 1 );
}
}
__________________________________________________________________________________________________
sample 31792 kb submission
class Solution {
public boolean checkPerfectNumber(int num) {
int sum=0;
if(num==0) return false;
for(int i=1;i<=num/2;i++)
{
if(num%i==0)
{
sum+=i;
}
}
if(sum==num)
{
return true;
}
else
{
return false;
}
}
}
__________________________________________________________________________________________________