-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipleofthree.java
52 lines (41 loc) · 1.06 KB
/
multipleofthree.java
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
45
46
47
48
49
50
51
52
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package multipleofthree;
import static java.lang.Math.abs;
import java.util.Scanner;
/**
*
* @author Harshita V
*/
public class Multipleofthree {
/**
* @param args the command line arguments
*/
static int checkformultiple(int n){
int odd_cnt=0,even_cnt=0;
if(n<0){n=-n;}
if(n == 0) return 1;
if(n == 1) return 0;
while(n>0){
if((n & 1)==1){
odd_cnt++;
}
n = n>>1;
if((1 & n)==1){ even_cnt++;
}
n=n>>1;
}
return checkformultiple(abs(odd_cnt-even_cnt));
}
public static void main(String[] args) {
// TODO code application logic here
Scanner input=new Scanner(System.in);
int num=input.nextInt();
if(checkformultiple(num)==1){
System.out.println("multiple");}
else{System.out.println("not multiple");}
}
}