Results 1 to 15 of 15
Like Tree6Thanks
  • 1 Post By Deveno
  • 1 Post By emakarov
  • 2 Post By topsquark
  • 1 Post By Plato
  • 1 Post By johng

Math Help - parity of numbers

  1. #1
    Newbie
    Joined
    Jan 2013
    From
    portugal
    Posts
    6

    parity of numbers

    Hey!

    Odd * Odd numbers are always odd correct??
    Can you check the following numbers?

    7^19,
    9^17,
    9^18,
    9^19 ? I have a program that says they are all divisible by 2.

    Isnt that peculiar?

    andrec
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member jakncoke's Avatar
    Joined
    May 2010
    Posts
    387
    Thanks
    80

    Re: parity of numbers

    What? I don't know if you are trying to troll.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,559
    Thanks
    785

    Re: parity of numbers

    Can you post the program and the name of the programming language?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Jan 2013
    From
    portugal
    Posts
    6

    Re: parity of numbers

    public class logic {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    double eSquare=0;
    int evenPlus1=0;
    for (int even = 0; even < 10; even+=2) {

    for (int n=0;n < 20; n+=1) {
    evenPlus1 =even+1;
    eSquare = Math.pow(evenPlus1,n); //(even+1)^n
    if ((eSquare % 2) ==0)
    System.out.println(evenPlus1+"^"+n+" "+eSquare+" is divisible by 2");
    }
    }
    }
    }

    its java.

    later,

    andrec
    Follow Math Help Forum on Facebook and Google+

  5. #5
    MHF Contributor

    Joined
    Mar 2011
    From
    Tejas
    Posts
    3,401
    Thanks
    762

    Re: parity of numbers

    since 2 is a prime and:

    7^{19} = 7(7^{18})

    either 2 divides 7 (clearly false) or 2 divides 7^{18}.

    rinse and repeat.
    Thanks from topsquark
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Newbie
    Joined
    Jan 2013
    From
    portugal
    Posts
    6

    Re: parity of numbers

    sorry didnt understodd..

    9=7^18??!?!?

    later,

    andrec
    Follow Math Help Forum on Facebook and Google+

  7. #7
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,559
    Thanks
    785

    Re: parity of numbers

    This effect is probably due to overflow. Double numbers are represented as m\cdot2^e where m is the mantissa and e is the exponent. Positive integers can only be represented precisely if they fit in the mantissa. According to this document, type double allots 53 bits to the mantissa. Interestingly, \log_2\left(7^{19}\right)=19\log_27\approx53.3, so 7^{19} requires 54 bits to be represented precisely. Therefore, as a double, it will be represented as m\cdot 2^1 for some m, which is an even number.
    Thanks from topsquark
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Newbie
    Joined
    Jan 2013
    From
    portugal
    Posts
    6

    Re: parity of numbers

    yep, i just tested it on windows calculator and it works there

    thanks..

    suprisingly the c code similiar to the java code has the same error


    andrec
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Forum Admin topsquark's Avatar
    Joined
    Jan 2006
    From
    Wellsville, NY
    Posts
    10,186
    Thanks
    404
    Awards
    1

    Re: parity of numbers

    Never ever trust a calculator over your own mind!

    -Dan
    Thanks from emakarov and Plato
    Follow Math Help Forum on Facebook and Google+

  10. #10
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,559
    Thanks
    785

    Re: parity of numbers

    Quote Originally Posted by andrec View Post
    suprisingly the c code similiar to the java code has the same error
    This must be because both C and Java implement the IEEE 754 standard for binary floating point numbers. This tutorial says, "This data type [float] should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead." Also, Java long type has 64 bits, so it can precisely represent positive integers up to 2^63 - 1, which is more than double can.
    Follow Math Help Forum on Facebook and Google+

  11. #11
    MHF Contributor

    Joined
    Aug 2006
    Posts
    18,925
    Thanks
    1764
    Awards
    1

    Re: parity of numbers

    Quote Originally Posted by topsquark View Post
    Never ever trust a calculator over your own mind!
    That is the whole of this opinion piece.
    It may be fifteen years old, but it is still true today.
    Thanks from topsquark
    Follow Math Help Forum on Facebook and Google+

  12. #12
    Newbie
    Joined
    Jan 2013
    From
    portugal
    Posts
    6

    Re: parity of numbers

    cheers,

    thanks to all (bigdecimal works fine)

    later,
    andrec
    Follow Math Help Forum on Facebook and Google+

  13. #13
    Super Member
    Joined
    Dec 2012
    From
    Athens, OH, USA
    Posts
    689
    Thanks
    281

    Re: parity of numbers

    Hi Andrec,

    If you are going to use Java for big integers, use BigInteger, not BigDecimal. Here's code for computing 7^19 mod 2:
    BigInteger seven = BigInteger.valueOf(7);
    BigInteger nineteen = BigInteger.valueOf(19);
    BigInteger two = BigInteger.valueOf(2);
    BigInteger odd = seven.modPow(nineteen, two);
    System.out.println(odd.toString());
    As expected, output is 1.
    A more interesting example is computing the last three digits of 151^192:
    BigInteger onefiftyone = BigInteger.valueOf(151);
    BigInteger oneninetytwo = BigInteger.valueOf(192);
    BigInteger thousand = BigInteger.valueOf(1000);
    BigInteger digits = onefiftyone.modPow(oneninetytwo, thousand);
    System.out.println(digits.toString());
    Output is 801
    You can do this example by hand, but I wouldn't want to.
    Thanks from emakarov
    Follow Math Help Forum on Facebook and Google+

  14. #14
    Newbie
    Joined
    Jan 2013
    From
    portugal
    Posts
    6

    Re: parity of numbers

    thks! i started using BigInteger....

    later,

    andrec
    Follow Math Help Forum on Facebook and Google+

  15. #15
    Newbie
    Joined
    Jan 2013
    From
    Vietnam
    Posts
    2

    Re: parity of numbers

    (2n+1) * (2n+1) with n is 1,...
    = 4n(2) + 2(2n+1)(2) + 1

    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Parity-check matrix
    Posted in the Advanced Algebra Forum
    Replies: 0
    Last Post: January 2nd 2012, 09:07 AM
  2. question on put call parity
    Posted in the Business Math Forum
    Replies: 4
    Last Post: May 21st 2011, 05:18 AM
  3. Parity of an expression
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: November 24th 2010, 01:44 PM
  4. Parity
    Posted in the Calculus Forum
    Replies: 2
    Last Post: April 14th 2008, 05:01 AM
  5. Parity
    Posted in the Advanced Algebra Forum
    Replies: 2
    Last Post: April 1st 2008, 07:20 PM

Search Tags


/mathhelpforum @mathhelpforum