Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given two positive numbers X and Y, check if Y is a power of X or not. Example 1: Input: X = 2, Y =

Given two positive numbers X and Y, check if Y is a power of X or not.

Example 1:

Input: X = 2, Y = 8 Output: 1 Explanation: 23 is equal to 8.

Example 2:

Input: X = 1, Y = 3 Output: 0 Explanation: Any power of 1 is not equal to 8.

Your Task:

You don't need to read input or print anything. Your task is to complete the function isPowerOfAnother() which takes an integer and returns 1 if y is the power of x, else return 0.

Expected Time Complexity: O(N) Expected Auxiliary Space: O(1)

Constraints: 1 <= x <= 103 1 <= y <= 108

// { Driver Code Starts //Initial Template for Java import java.io.*; import java.util.*;

class GFG { public static void main(String args[])throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); while(t-- > 0) { String[] inp=read.readLine().split(" "); Long X=Long.parseLong(inp[0]); Long Y=Long.parseLong(inp[1]);

Solution ob = new Solution(); System.out.println(ob.isPowerOfAnother(X,Y)); } } } // } Driver Code Ends

//User function Template for Java class Solution{ static Long isPowerOfAnother(Long X, Long Y){ // code here } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions