You are viewing a single comment's thread. Return to all comments →
This does not work for 1000000 input , it crashes .
#include < bits/stdc++.h >
using namespace std;
int n,q,i,j; int dp[2000000]; int flag[2000000];
int recursion(int N) {
// cout<
if(N<=3) return n; if(dp[N]!=-1) return dp[N]; int x=recursion(N-1)+1; int y=2147483647; for(int i=2; i*i<=N; i++) if(N%i==0) y=min(y,recursion(N/i)+1); dp[N]=min(x,y); return dp[N];
}
int main() {
memset(dp,-1,sizeof(dp)); scanf("%d",&q); while(q--) { scanf("%d",&n); printf("%d\n",recursion(n)); } return 0;
} /* 14 1 42 2 1 14 3 1 28 3 1 60 1 78 2 2 3 3 2 3
*/
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 →
This does not work for 1000000 input , it crashes .
#include < bits/stdc++.h >
int n,q,i,j; int dp[2000000]; int flag[2000000];
int recursion(int N) {
// cout<
}
int main() {
} /* 14 1 42 2 1 14 3 1 28 3 1 60 1 78 2 2 3 3 2 3
*/