You are viewing a single comment's thread. Return to all comments →
I have got the logic I believe, but I am not able to pass any of the test cases. Could anyone please help ?
#include <bits/stdc++.h> using namespace std; #define MAXI 1000001 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int queries; cin>>queries; int dp[MAXI]; memset(dp, 0, sizeof(dp)); dp[0]=0; dp[1]=1; for(int i=2;i<MAXI;i++) { dp[i]=dp[i-1]+1; } for(int i=0;i<MAXI;++i) { for(int j=2;(j<=i) && ((i*j)<MAXI);++j) { dp[i*j]=min(dp[i*j], dp[i]+1); } } for(int i=0;i<queries;i++) { int num; cin>>num; cout<<dp[num]<<endl; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Down to Zero II
You are viewing a single comment's thread. Return to all comments →
I have got the logic I believe, but I am not able to pass any of the test cases. Could anyone please help ?