i was actually trying this problem.. www.spoj.pl/problems/LQDCANDY
I'm getting WA still.. #include<math.h> #include<stdio.h> int cnt; inline int find_cuts(int l,int rope) { if(l==rope) return cnt; cnt++; l=l/2; if(l==rope) return cnt; if(rope>l) rope-=l; return find_cuts(l,rope); } int main(){ int t; scanf("%d",&t); while(t--){ int n,needed; scanf("%d",&n); int x=log2(n); int p=(int)pow(2,x); if(n!=p) needed=(int)pow(2,x+1); else{ printf("%d 0\n",n); continue; } if(n%2==1) printf("%d %d\n",needed,(int)log2(needed)); else{ cnt=0; printf("%d %d\n",needed,find_cuts(needed,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.