My code is not working, if I don’t do the prime factorization for k and directly do it for the number k given by raising the power of k and finding the no. of divisors of k.
May I know the reason why is it not working.?
My code not workinng
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll t; cin>>t; while(t–) { ll n,k; cin>>n>>k; ll lg = log(n)/log(k); ll sum=0; //cout<<lg<<endl; for(ll i=1;i<=lg;i++) { sum+=(n/pow(k,i)); } cout<<sum<<endl; } return 0; }
How are you getting this equation, like it should be log(n!)/log(k). Could you please write out your approach, I am not able to figure it out.