MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / isPower

Method isPower

InterviewBit_problems/Math_Section/Solution.cpp:5–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3 A and P both should be integers.*/
4
5 int Solution::isPower(int A) /*The function that returns appropriate output*/
6 {
7
8 if(A==1) return 1; //condition met as mentioned in problem statement
9
10 for(long long int i=2;i*i<=A;i++)//start from 2 ;if start by 1 ;TLE as loop continues.
11 {
12 unsigned y=2;
13 unsigned p=pow(i,y);//function pow from math library
14 while(p<=A && p>0)
15 { if(p==A)
16
17 { return 1;}
18 y++;
19 p=pow(i,y);
20
21 }
22 }
23 return 0;
24 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected