正整数1到n连续排列组成的大整数,计算n最小为多少时,它是1到20的倍数。
大整数结构如下:
12345678910111213141516…99100101102…
关于大整数的高效算法
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
微笑精灵 2022-06-27 16:43关注public static void main(String[] args) { long l = System.currentTimeMillis(); System.out.println(l); BigInteger start=new BigInteger("1") ; BigInteger step=new BigInteger("1") ; BigInteger nuber=BigInteger.ONE; BigInteger bit=BigInteger.TEN; while (true){ start=start.add(BigInteger.ONE); if (check(nuber= nuber.multiply(bit.pow(start.add(step).toString().length())).add(start))){ System.out.println(start); System.out.println(nuber); break; } } System.out.println(System.currentTimeMillis()-l); } private static boolean check(BigInteger start) { if (start.remainder(BigInteger.valueOf(20)).compareTo(BigInteger.ZERO)!=0) return false; for (int i = 11; i<20; i++) { if (start.remainder(BigInteger.valueOf(i)).compareTo(BigInteger.ZERO)!=0) { return false; } } return true; }这好像跟高效不太沾边……
也许可以把1-20处理一下只要其中的素数。
写出来了,但是跑不出来,小水管,扛不住解决 无用评论 打赏 举报 编辑记录