@Sunny: the value can still overflow because Using the while loop u r dividing the res value whenever possible. so the while checks if the current j divides res or not. What if current res value is not divisible by that particular j ... it will multiply by i for next res value and it will keep doing this until u get a res value divisible by that specific current j. So in the meantime, when the res value is increasing just because j doesn't divide it, it can overflow.
On Jun 21, 4:12 pm, sunny agrawal <sunny816.i...@gmail.com> wrote: > i am doing the same thing without using array > > long long int res = 1; > int j = 2; > for(int i = n-k+1; i <= n; i++){ > res *= (long long int)i; > while(j <= k && res%j == 0){ > res/=j; > j++; > } > } > > On Tue, Jun 21, 2011 at 4:25 PM, kartik sachan <kartik.sac...@gmail.com> > wrote: > > > > > > > @ sunny i am not getting ur apporach > > but i am thinking like this...... > > taking an array from and intilize it to n to n-r > > > a[1000]; > > int k=0; > > for(int i=n;i>=n-r;i--) > > a[k++]=i; > > > for(int y=n-r;y>1;y--) > > for(j=0;j<k;j++) > > if(a[j]%y==0) > > {a[j]=a[j]/y;break;} > > > for example we take 7c3 > > > so first array is intilize to {7,6,5,4} > > then we check divisibilty by {3,2} > > so 6 is divisible by 3 so put 6/3 back in array 2 > > so finally 7*2*5*2; > > > -- > > 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. > > -- > Sunny Aggrawal > B-Tech IV year,CSI > Indian Institute Of Technology,Roorkee- Hide quoted text - > > - Show quoted text - -- 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.