Surprising result from Math.pow(65,17) 233

前端 未结 2 1751
自闭症患者
自闭症患者 2021-01-26 05:56

For some reason when dealing with large numbers, the modulus operator doesnt give me the correct output, have a look at the code

double x = Math.pow(65,17) % 323         


        
2条回答
  •  半阙折子戏
    2021-01-26 06:27

    You can use int like this

    int n = 65;
    for (int i = 1; i < 17; i++)
        n = n * 65 % 3233;
    System.out.println(n);
    

    or BigInteger like

    System.out.println(BigInteger.valueOf(65).pow(17).mod(BigInteger.valueOf(3233)));
    

    both print

    2790
    

提交回复
热议问题