-1

问题 125 如链接中所述,代码必须将所有可以写为连续平方和的回文求和。它适用于他们的示例(1000 的输出为 4164),但比问题本身的预期略大。使用谷歌我发现正确的值是 2906969179,但我的代码给出了 2916867073。

public static void main(String[] args)
{
    long current,start=1,sum,total=0;
    while(start<10000)
    {
        current=start+1; sum=start*start;
        while(current<10000)
        {
            sum+=current*current; 
            if(sum>use.pow(10, 8)) break;
            current++; 
            if(use.isPalidrom(BigInteger.valueOf(sum))) total+=sum;
        }
        start++;
    }
    System.out.println(total);
}

如果有帮助,这里是所有回文的列表以及产生它们的连续数字(根据我的代码):

5 1...2
55 1...5
1992991 1...181
505 2...11
818 2...13
42924 2...50
77 4...6
636 4...12
1001 4...14
1771 4...17
595 6...12
1441 6...16
34277243 7...468
63866836 8...576
181 9...10
17371 9...37
554455 9...118
434 11...13
1111 11...16
148841 11...76
313 12...13
166661 14...79
545 16...17
11600611 16...326
3242423 17...213
485584 18...113
6446 19...29
21712 19...41
95177159 21...658
99199 22...67
8424248 22...293
981189 23...143
9313139 26...303
363363 27...103
3015103 27...208
17871 29...42
635536 29...124
97679 31...68
46564 32...55
1365631 34...160
5479745 36...254
4334 37...39
63844836 41...576
127721 44...77
6277726 46...266
46433464 46...518
19691 50...56
108801 50...76
444444 51...113
65756 54...70
6546456 54...270
6843486 54...274
1077701 63...151
139931 69...90
44444 71...78
9105019 72...302
5367635 73...254
6106016 74...265
81818 77...88
525525 77...126
904409 83...148
52155125 83...539
646646 85...136
982289 88...153
435534 92...127
138831 93...106
18244281 93...381
51015 99...103
41214 100...103
4776774 101...248
3628263 102...228
9343439 102...307
171171 104...117
656656 106...146
1949491 106...191
161161 116...126
188881 126...136
4424244 128...248
9940499 136...318
5718175 146...272
137731 149...154
923329 151...183
1681861 156...206
18699681 158...391
6844486 159...290
11922911 160...341
1972791 164...217
9435349 167...320
4211124 172...260
9814189 172...325
629926 173...191
1224221 173...206
191191 176...181
45555554 182...522
2176712 189...236
45755754 192...524
68688686 194...597
37533573 197...493
494494 207...217
5276725 210...292
17488471 215...396
9838389 223...343
7355537 224...321
5588855 226...304
16955961 226...396
56722765 239...568
972279 257...270
5603065 261...325
47622674 261...543
50244205 275...555
944449 288...298
52344325 292...566
26744762 304...476
97299279 312...685
53166135 315...575
67233276 320...616
554455 331...335
69933996 331...626
52722725 341...582
12888821 409...474
44366344 412...587
5536355 415...444
58366385 421...629
69388396 429...659
16755761 471...536
9334339 477...514
15822851 479...539
9793979 482...520
10711701 491...531
66999966 539...709
964469 566...568
92800829 577...777
18422481 589...637
2904092 599...606
4338334 623...633
6523256 631...646
40211204 632...719
53933935 645...754
9343439 657...677
9072709 682...700
5090905 709...718
41577514 742...810
6831386 749...760
13922931 785...806
53211235 793...869
9563659 820...833
6780876 864...872
56800865 895...960
1690961 919...920
72299227 924...1001
43699634 975...1018
55344355 976...1030
62988926 1075...1126
32344323 1202...1223
32611623 1207...1228
16399361 1216...1226
3162613 1257...1258
3187813 1262...1263
69722796 1284...1324
11122111 1359...1364
57488475 1606...1627
5258525 1621...1622
5824285 1706...1707
9051509 1736...1738
49066094 2107...2117
64633646 2419...2429
51488415 3207...3211
95544559 3988...3993
4

1 回答 1

3

啊哈!我终于想通了。正如我所怀疑的,一些数字可以通过不同的连续平方和来实现。例如,554455 既可以表示为 331^2 + 332^2 + ... + 335^2 的总和,也可以表示为 9^2 + 10^2... + 118^2 的总和。

于 2013-08-16T15:18:18.583 回答