/*
we will be given a number "n" and "k" value we have to check whether
the n can be written as power of k
example : n=27 and k=3
27 = 3^3
so the output will be true
*/


#include<iostream>
using namespace std;

int ispower(int n,int k){
    if(n==0){
        return 0;
    }
    else{
        while(n!=1){
            if(n%k!=0)
                return 0;
            n=n/k;    
        }
        return 1;
    }
}

int main(){
    int n,k;
    cin>>n>>k;
    int flag=ispower(n,k);
    if(flag==1){
        cout<<"TRUE\n";
    }
    else{
        cout<<"FALSE\n";
    }
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: