Hello, I tried the question using single array. Condition on n,d given is 1000000. So array size goes the same right?
#include<stdio.h> #include<stdlib.h> int f(int n,int d); int dp[1000000]; int main() { int n,d,k,t; while(1) { for(t=0;t<1000000;t++) dp[t]=0; scanf("%d %d",&n,&d); if((n==0)&&(d==0)) break; else printf("%d %d %d\n",n,d,f(n,d)+1); } //system("PAUSE"); return 0; } int f(int n,int d) { if(n==1) return 0; return dp[n]?dp[n]:(dp[n]=(f(n-1,d)+d)%n); } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.