Help me in solving SMOL problem

My issue

help

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes her
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n>>k;
	    int ans=0;
	    if(n%k==0)
	    ans=0;
	    else{
	        while(n>0)
	    {
	        ans=n%k;
	        n=n/k;
	    }
	    }
	    
	    cout<<ans<<endl;
	}
	return 0;
}

Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone

@ashi39775
Your logic is not right .
Plzz refer my c++ solutiuon for better understanding .

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k;
	    cin>>n>>k;
	    if(k==0)
	    cout<<n;
	    else
	    cout<<n%k;
	    cout<<endl;
	}
	return 0;
}
1 Like