My issue
include <bits/stdc++.h>
using namespace std;
define inf INT_MAX
vectordp;
int fbu(int a,int b,int k){
dp.clear();
dp.resize(1000000000);
for(int x=a;x<=b;x++){
dp[x]= 1+ min(dp[x+1],(x%k==0)? dp[x*k]: inf);
}
return dp[b];
}
int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int a,b,k;
cin>>a>>b>>k;
cout<<fbu(a,b,k)<<endl;
}
}
anyone please tell me what is wrong in this code…
My code
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
int f(int a,int b,int k){
//Basic recursion approach
//T.C.= 2^n
if(a==b ) return 0;
// if(b==k) return 1;
return 1+ max(f(a+1,b,k), (a%k==0) ? f(a*k,b,k) : inf);
}
vector<int>dp;
int fbu(int a,int b,int k){
dp.clear();
dp.resize(1000000000);
for(int x=a;x<=b;x++){
dp[x]= 1+ min(dp[x+1],(x%k==0)? dp[x*k]: inf);
}
return dp[b];
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int a,b,k;
cin>>a>>b>>k;
cout<<fbu(a,b,k)<<endl;
}
}
Problem Link: Change A to B Practice Coding Problem