I am getting crct for given test cases but while submitting wrong answer

i am getting crct for given test cases but while submitting wrong answer

#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
long long int n,m;

	cin>>n>>m;
	long long int x=m;
	long long int sum=0;
	while(n>=x){
	   sum=sum+(n/x);
		x=x*m;
		
	}
	
	
	cout<<sum<<endl;
}

}

@coe17b014
Your logic is incorrect, Consider this testcase
1
6 4
output should be β€œ2” since 6! = 720%4^2 = 720 %16 =0. But your code is giving β€œ1” as output. Please go though hint video…

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.