Largest Integer Divisor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Echoing
    New Member
    • Nov 2007
    • 2

    Largest Integer Divisor

    I need to drawraw a flowchart for a algorithm which finds the largest proper divisor of n (that is, the largest m such that 1 <= m < n and m evenly divides n). You can use the % operator: recall that n % m is the remainder when n is divided by m.

    I need to test it on numbers such as 8,876,044,532,8 98,802,067 and 2,305,843,009,2 13,693,951..

    so far I have
    public class xc14 {

    public static long maxDiv(long n )
    {
    int m = 2;
    while(m <= (int) Math.sqrt(n))
    {
    // ...
    }
    return 1;
    }

    can anyone help?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Echoing
    I need to drawraw a flowchart for a algorithm which finds the largest proper divisor of n (that is, the largest m such that 1 <= m < n and m evenly divides n). You can use the % operator: recall that n % m is the remainder when n is divided by m.

    I need to test it on numbers such as 8,876,044,532,8 98,802,067 and 2,305,843,009,2 13,693,951..

    so far I have
    public class xc14 {

    public static long maxDiv(long n )
    {
    int m = 2;
    while(m <= (int) Math.sqrt(n))
    {
    // ...
    }
    return 1;
    }

    can anyone help?
    So where have you used the % operator like was suggested?

    Comment

    • Echoing
      New Member
      • Nov 2007
      • 2

      #3
      lol thats why im confused....

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Echoing
        lol thats why im confused....
        But you are trying to find numbers which divide perfectly into a given number N, For those numbers N % number is zero.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Suppose for a number N you have to find the largest proper divisor; this is equivalent
          to finding its smallest proper divisior; suppose the smalles one is 'S'; this implies
          that S*L == N where L happens to be the largest proper divisor of N.

          kind regards,

          Jos

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by JosAH
            Suppose for a number N you have to find the largest proper divisor; this is equivalent
            to finding its smallest proper divisior; suppose the smalles one is 'S'; this implies
            that S*L == N where L happens to be the largest proper divisor of N.

            kind regards,

            Jos
            Spoil sport

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by r035198x
              Spoil sport
              I really thought that this thread would brings us to BigIntegers and such; what
              I wrote is trivial isn't it?

              kind regards,

              Jos

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by JosAH
                I really thought that this thread would brings us to BigIntegers and such; what
                I wrote is trivial isn't it?

                kind regards,

                Jos
                We'll need to get to BigIntegers at some point.

                You couldn't have written anything more trivial if you had tried.

                Comment

                Working...