forgot to assign: m = n; On Sun, Oct 14, 2012 at 2:27 AM, Piyush Grover <piyush4u.iit...@gmail.com>wrote:
> The number which has 5 as last digit can be written as > n = 4*a + b where b = 1 or 3 > so if 4*a + 1 == n or 4*a + 3 == n; then n has 5 as a last digit. > So code looks like: > > void main() > { > int n, m; > scanf("%d", &n); > m >>= 2; > m <<= 2; > if(add(m, 1) == n || add(m,3) == n) > puts("yes"); > else > puts("no"); > } > > int add(int x, int y) { > > int a, b; > > do { > > a = x & y; b = x ^ y; x = a << 1; y = b; > > }while(b); > > return b; > > } > > > On Fri, Oct 12, 2012 at 12:46 AM, Dave <dave_and_da...@juno.com> wrote: > >> @Jaspreet: The % operator is implemented using division, which is >> considered an arithmetic operation, not a bitwise operation. >> >> On primitive chips, as may be used in specialized hardware, division may >> not be implemented, in which case a non-division based algorithm may be >> desired. >> >> The question may be based on that idea, or just on how to do it faster >> than using division, which typically is a very slow instruction (compared >> to other machine instructions). >> >> Dave >> >> On Thursday, October 11, 2012 4:14:17 AM UTC-5, Jaspreet Singh wrote: >> >>> Nice solution Dave sir .. but if you know can you please tell us what is >>> the internal structure of "%" operator .. i mean it has also to be done by >>> bitwise any way .. so can't we implement that in HHLs. >>> >>> Thanks >>> >>> On Thu, Oct 11, 2012 at 1:25 AM, Dave <dave_an...@juno.com> wrote: >>> >>>> @Mohit: The decimal representation of a number ends in 5 if its low >>>> order bit is 1 and it is divisibile by 5. >>>> >>>> An algorithm using bitwise operations to check for divisibility by 5 is >>>> given at https://groups.google.com/d/**msg/algogeeks/I5HWmwKW_ks/** >>>> n38FWJSd0l8J<https://groups.google.com/d/msg/algogeeks/I5HWmwKW_ks/n38FWJSd0l8J>. >>>> >>>> >>>> It probably is not as fast as (n & 1) && (n % 5 == 0), though. >>>> >>>> Dave >>>> >>>> On Wednesday, October 10, 2012 4:06:28 AM UTC-5, mohit mishra wrote: >>>> >>>>> >>>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To view this discussion on the web visit https://groups.google.com/d/** >>>> msg/algogeeks/-/bRupe9F1MUIJ<https://groups.google.com/d/msg/algogeeks/-/bRupe9F1MUIJ>. >>>> >>>> >>>> To post to this group, send email to algo...@googlegroups.com. >>>> To unsubscribe from this group, send email to algogeeks+...@** >>>> googlegroups.com. >>>> >>>> For more options, visit this group at http://groups.google.com/** >>>> group/algogeeks?hl=en <http://groups.google.com/group/algogeeks?hl=en>. >>>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/algogeeks/-/XF05MQd7Ne4J. >> >> 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. >> > > -- 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.