-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisPowerOfFour.java
More file actions
36 lines (30 loc) · 815 Bytes
/
isPowerOfFour.java
File metadata and controls
36 lines (30 loc) · 815 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
/* 342. Power of Four
* Given an integer n, return true if it is a power of four. Otherwise, return false.
An integer n is a power of four, if there exists an integer x such that n == 4x.
*
* Input: n = 16
Output: true
*
* Input: n = 5
Output: false
*/
import java.util.Scanner;
public class isPowerOfFour {
static Scanner scan = new Scanner(System.in);
public static boolean solve(int num, int p){
double res = Math.pow(4, p);
//BC
if(res > num) return false;
//MC
if(res == num) return true;
//RC
return solve(num, p+1);
}
public static boolean solve(int num){
return solve(num, 0);
}
public static void main(String[] args) {
int num = scan.nextInt();
System.out.println(solve(num));
}
}