InterviewBit - power of two integers  

by ne on 2021-09-29 under Algo/DS/Problems tagged with interviewbit

This problem is a property of InterviewBit (www.interviewbit.com). Full details of the question, and if you want to try it out yourself, proceed to interviewbit : https://www.interviewbit.com/problems/power-of-two-integers/

Here's the implementation:


public class Solution {
    public int isPower(int A) {
        if(A==1) return 1;
        int sqrm=1+(int)Math.sqrt(A);
        for(int i=2;i<=sqrm;i++){
            int n=A;
            while(n!=0){
                if(n%i!=0 && n!=1) break;
                n=n/i;
                if(n==1) return 1;
            }
        }
            
        
        return 0;
    }
}