Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Created September 9, 2012 21:27
Show Gist options
  • Save pcarrier/3687418 to your computer and use it in GitHub Desktop.
Save pcarrier/3687418 to your computer and use it in GitHub Desktop.
% java -cp target/classes PrimeSum 1000
There are 168 primes <= to 1,000.
Their sum is 76,127.
Their product is 19,590,340,644,999,083,431,262,508,198,206,381,046,123,972,390,589,368,223,882,605,328,968,666,316,379,870,661,851,951,648,789,482,321,596,229,559,115,436,019,149,189,529,725,215,266,728,292,282,990,852,649,023,362,731,392,404,017,939,142,010,958,261,393,634,959,471,483,757,196,721,672,243,410,067,118,516,227,661,133,135,192,488,848,989,914,892,157,188,308,679,896,875,137,439,519,338,903,968,094,905,549,750,386,407,106,033,836,586,660,683,539,201,011,635,917,900,039,904,495,065,203,299,749,542,985,993,134,669,814,805,318,474,080,581,207,891,125,910.
Computed in 0.003sec.
% java -cp target/classes PrimeSum 10000
There are 1,229 primes <= to 10,000.
Their sum is 5,736,396.
Their product is 59,490,679,579,998,635,868,564,022,242,503,445,659,680,322,440,679,327,938,309,703,916,140,405,638,383,434,744,833,220,555,452,130,558,140,772,894,046,169,700,747,186,409,941,317,550,665,821,619,479,140,098,743,288,335,106,272,856,533,978,719,769,677,794,737,287,419,461,899,922,456,614,256,826,709,727,133,515,885,581,878,614,846,298,251,428,096,512,495,590,545,989,536,239,739,285,290,509,870,860,732,435,109,794,045,491,640,561,011,775,744,617,218,426,011,793,283,330,497,878,491,137,999,673,760,740,717,904,979,730,106,994,180,691,956,740,996,319,139,767,941,335,979,146,924,614,249,205,862,051,182,094,081,815,447,356,600,355,657,858,936,442,589,201,739,350,474,320,966,093,143,098,768,914,226,528,498,860,747,050,474,426,418,211,313,776,073,365,498,029,087,492,308,102,876,323,562,641,651,940,555,529,817,223,923,967,479,711,293,692,697,592,800,750,806,084,802,623,966,596,666,156,361,791,014,935,954,720,420,383,555,300,213,829,134,029,560,826,306,201,326,905,674,141,090,667,002,959,274,513,478,562,033,467,485,802,590,354,539,887,133,866,434,256,562,999,666,615,074,220,857,502,563,011,098,759,348,850,149,774,083,443,643,246,907,501,430,076,141,377,431,759,984,926,248,272,553,982,527,014,011,245,310,690,986,644,461,251,576,837,779,050,124,866,641,531,488,351,016,070,300,247,918,750,613,207,952,783,437,248,236,577,750,579,092,103,591,540,592,540,838,395,240,861,443,615,842,939,673,889,972,504,776,455,114,767,522,430,347,610,500,271,801,944,701,491,874,649,306,605,557,851,914,677,316,523,034,726,044,356,368,337,787,113,190,245,601,235,705,959,816,327,016,988,315,321,850,324,065,292,964,680,148,884,818,699,916,224,411,245,926,491,625,245,571,963,741,062,587,277,736,372,090,007,125,908,660,590,314,049,976,206,281,064,703,285,728,879,581,199,596,401,313,352,724,403,492,043,120,507,597,057,004,633,720,111,008,838,673,185,885,941,472,392,623,805,512,709,896,864,520,875,740,497,617,898,566,981,218,781,313,900,004,406,341,154,884,180,472,153,171,064,617,953,661,517,880,143,988,867,189,622,824,081,729,539,392,205,701,820,144,922,307,223,627,345,876,707,465,251,206,005,262,622,236,311,161,449,785,941,834,002,795,854,996,108,322,186,230,425,179,217,618,301,526,151,712,928,790,928,933,798,369,678,844,576,216,735,378,555,233,905,935,973,195,721,247,604,933,753,363,412,045,618,703,247,367,192,610,615,234,835,041,956,551,569,232,557,323,060,407,648,325,565,048,712,478,527,583,315,981,204,846,341,857,095,134,567,470,182,330,491,262,285,172,727,037,299,211,391,244,340,592,936,174,221,176,781,260,586,188,162,350,081,192,408,213,470,101,717,320,475,998,863,222,409,777,310,443,027,421,196,981,193,126,541,663,212,124,245,716,187,453,863,438,039,402,316,877,152,286,468,198,891,603,632,606,578,778,749,292,403,571,792,687,832,081,974,134,637,014,026,451,921,536,576,338,243,322,267,400,651,083,805,535,119,025,415,817,887,075,652,758,045,539,565,968,044,552,126,338,330,231,434,466,204,888,993,650,859,153,585,380,124,240,540,573,308,417,330,478,048,240,203,241,631,072,371,322,849,430,883,727,355,239,704,116,556,046,700,749,530,006,852,187,064,160,849,175,332,758,172,150,251,213,637,470,549,781,080,491,037,088,372,092,203,085,237,973,008,861,896,576,796,238,915,011,886,636,658,033,019,385,943,299,986,285,181,723,378,096,425,117,379,056,207,797,455,963,451,889,971,988,904,466,449,319,007,760,192,467,211,209,692,128,894,691,704,353,648,198,130,409,333,996,534,250,878,389,064,152,054,828,983,825,841,234,644,875,996,912,485,916,827,004,219,887,033,833,599,723,481,903,489,316,488,764,021,700,996,686,817,244,736,947,119,285,629,049,355,809,027,206,179,193,628,292,018,441,744,552,168,286,541,735,687,924,729,198,455,883,895,791,600,170,372,255,284,216,915,442,808,139,396,541,702,893,732,917,062,958,054,499,525,549,626,455,191,658,842,064,247,047,426,187,897,146,172,971,001,949,767,308,335,268,505,414,284,088,528,125,611,263,685,734,457,560,292,833,389,995,980,698,745,893,243,832,547,007,166,243,476,192,958,601,735,336,260,255,598,581,701,267,151,224,204,461,879,782,815,468,518,040,925,292,817,115,377,696,676,461,775,120,750,971,210,951,527,384,637,825,092,221,708,015,393,564,320,979,357,698,186,262,039,029,460,777,050,248,162,599,194,429,941,464,248,920,952,161,182,024,344,007,059,684,970,270,762,248,243,899,640,259,750,891,406,957,836,740,989,312,390,963,091,260,380,990,901,672,119,736,141,666,856,448,171,380,781,556,117,025,832,312,710,039,041,398,538,035,351,795,267,732,240,730,608,951,176,127,282,191,528,457,681,241,590,895,740,457,571,038,936,173,983,449,289,126,574,141,189,374,690,274,057,472,401,359,482,497,502,067,814,596,008,557,725,079,835,212,621,242,944,853,319,496,441,084,441,343,866,446,380,876,967,613,370,281,793,088,540,430,288,658,573,281,302,876,742,323,336,651,987,699,532,240,686,371,751,448,290,351,615,451,932,054,274,752,105,688,318,766,958,111,191,822,471,878,078,268,490,672,607,804,265,064,578,569,581,247,796,205,593,441,336,042,254,502,454,646,980,009,177,290,888,726,099,355,974,892,680,373,341,371,214,123,450,598,691,915,802,122,913,613,669,446,370,194,221,846,225,597,401,405,625,536,693,874,723,700,374,068,542,217,340,621,938,985,167,525,416,725,638,580,266,200,550,048,001,242,788,847,319,217,369,432,802,469,735,271,132,107,428,204,697,172,144,851,088,692,772,696,511,622,350,096,452,418,244,968,500,432,645,305,761,138,012,204,888,798,724,453,956,720,733,374,364,721,511,323,104,353,496,583,927,094,760,495,687,785,031,050,687,852,300,161,433,757,934,364,774,351,673,531,859,394,855,389,527,851,678,630,166,084,819,717,354,779,333,605,871,648,837,631,164,630,550,613,112,327,670,353,108,353,791,304,451,834,904,017,538,583,880,634,608,113,426,156,225,757,314,283,269,948,216,017,294,095,002,859,515,842,577,481,167,417,167,637,534,527,111,130,468,710.
Computed in 0.021sec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment