{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":50913,"title":"Compute the nth term from the golden sieve","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 165px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 82.5px; transform-origin: 407px 82.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/45367\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003eCody Problem 45367\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 129.5px 8px; transform-origin: 129.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved the Sieve of Eratosthenes, and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/50811-compute-the-nth-term-from-the-sieve-of-flavius-josephus\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003eCody Problem 50811\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 94px 8px; transform-origin: 94px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved the Sieve of Flavius Josephus. To apply the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 39.5px 8px; transform-origin: 39.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003egolden sieve\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 133.5px 8px; transform-origin: 133.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, start with the natural numbers and at the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 129px 8px; transform-origin: 129px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth step, take the sequence, which we will call \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ea\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 87px 8px; transform-origin: 87px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADsAAAAlCAYAAAD8+ZFYAAACUklEQVRoge2YXZWDMBCFPw9xUAMYQEEV1AEOcFALaKgEPNQCGrDAPpA5mdIJSbpA+8B92tOwM3PnP4ETJ06csOGAZkN5NVBtKG8zOKBnW+Mc8ABuG8r8NxzwZJ8oiOyfIdwD7Y7yHTDwAyndekP2RsMc4a/BASPHpdjAvhm0iqOiqvWNB+p7wQjcD9R3ASa+0KyuXvH1YL0D8zjaBBXzMHfqt5rZqxp3ZrKOMlwMWZbOGB78M5UdoR4e/u+eQGjive33/vcUGi9HvteyauZIye9P0oRb/+3SYVmolEJNyCkjLE+OnkCOfEn5idDQboRO/lDnqbIQsnWG7jdDRuzIoQzoImc5ZOHVcS0zoYEQxVadpyJW80GT0kStf9QGWuclZHVkr16vJiWRzVkahGzRvH0mFGgDrToqISu1P2LvuVJGOQSKyd5I10jHujNKyOomtCyJSp3l1GHxyBPlse1HhvdEfGkYyCOrZVlZ0hBvghaKGpT2ZIxIR9rbJaNHZFkXe6nX3EVByGbNd63cSoWa9Ugslaa6px4rsdov6a49Bfu4bvNLstKhl93xxntUJENStSO6rMjpJnghXNTXMGKPQhNagU7j2gvSS8admaieiRpDQrHOEityugkK0TXnibyihWK5oj0JRFFnI3GiEFbM2LleN61vJINET+qxruODK6Uj7KvWg1bjz5qIkVrO2uVddMQaYaVsSEVLdB19y3qBbESlt59SiOO+jo6CpvEBpJ/s7dBs9OzzgvAzL4tLdGxLeI+H902xZQPJfb04ceLEid/HH7ed5mf0eC3FAAAAAElFTkSuQmCC\" alt=\"a(n)\" style=\"width: 29.5px; height: 18.5px;\" width=\"29.5\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 30.5px 8px; transform-origin: 30.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 119.5px 8px; transform-origin: 119.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn the first step, delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAlCAYAAACao20PAAACgElEQVR4nO2abbGjMBRAj4c4WAMYQEEV4AAHdYAFNCABD7WABix0fyQZ8vqSlnywhO49M8y8eSUh5OTjXgAEQRAEQTgaBfQF62uBpmB9whsUMFO2wxUwAV3BOgUPCngQL2/P+bbub5RYzeoyA/eI81tTZt15vgIWKrrhTDr0/UxnNwS0uGXnuQ1a3NMcewWC3lsfcU2rjhu6r+z9ny5QoSXsWd56tOybKRMrEPTNx8z0mhjQfdBTkcCY2ediZ2GswHtCmRqpRuCKHlmxpAr8Y8pdPaCpQuDNNOKWUDZVIFS0+WdwqMAGHSUq538tevS7DKYRinhyBE6J5WqiuEDFtr9M5u+ZTdKT3yG8lZBCjsC7Kfs6oPZgB2fukUtRgQ1baOtKUrwP91e0iBRKCEzpSDeFST1KzP5iAhu2kN6XJNsLjYHfzhDYkh7IDObaOUeJWVNEoCvP1xnuDPT9frbAq+aDUEjgw1QSerpho8xQoCIC08kW2DmVhNKAkfeCzxKYk77UQrZAG7SEnqLYhPlJOFFfuF4Q8xVRaMNnOaNzTqjBZ6cROfnnpaNQ92Gqbxlq+dngUEfl5GM5AmfSnr/Cl0ShtuN9Am1kOvFz/+v4/amEncn/+lHaij+tuRJZAt3o0l1CW3TnuIn9wPby0TcTF9I6M1WgXR1K7ENnUiyIsbPswSbPvcBKWB5sj99i9qPXJTpGxkj68lkL7gq4kLYFodj2A99HQ735ree9nJgXui1agG9fGfi8FNtrXTV96NB97bv/Oyd+LmLfsKdEhTHYASccwMixgYXdn48eJP81M8e8Kf+2L9KqZqSsxCM+FhY+UDLIeP0yQBAEQRAEQbgKfwHdzFGGzPiz9wAAAABJRU5ErkJggg==\" style=\"width: 56px; height: 18.5px;\" width=\"56\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 231.5px 8px; transform-origin: 231.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position to get 2, 3, 4, 5, 6, 7,…Then in the second step, delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAlCAYAAACao20PAAADI0lEQVR4nO2a4Y2DMAxG3w5swAIswASdoBt0g27ACp2hI3SHW6EzdIXej2Dh0pCYEARUeRLS6QqB2LH9OQCFQqFQKBTWpgIuGcdrgSbjeIUAFfAgr8Er4A6cM45Z8FABf9icV+EiqwXqGWP/ihP1/HfDA7hGzmn6896j40l8MlV/3pHT6Qm3EMfz73Dz24wrzrghTnw/+Pg4Rca44AxwRM64OcpC73A2e6v/b0IFvAinNznnwWeknfiOyNhKfBKP9L3R4p7bt0BvDHPfJKVaoq/DRc6Uc7QTYwr2ilsMRyIk7Grsc1+FF85BsXNCtUun13tkLJnwUQRNRfxZrSUkO2L40I1rXJqIYXUguIi3nHcEZEE+yShkGlw+1gP6JH+HrW5ZEAda6tud46XRKa5kir6Kob7c+78fDE56850GpXYtRdcBS5sgk7b0kGNkcS49cnDG2Xux8xoGSasNWDEY1rfiRVkuRUtsC+LAFEP6+tC5x9Lob3BBosdLFjBNP8DU6peb+OpYrv5FjGpt0lvShUzX32/JsaT+yv11D6gb+llo5/mMoSPQ93sOB4oz5vR2KdfskZrPSJyziIFhW2dqd0PLe59QWepA2R6zqFTNrzhQ0DrDPCepOyEFJLsEUw5e6sB7f/1cFWtpX46EznTm9Cw5eGoXRSvDqdz8JN2BN9KcB8tEzJ5UqEZ0gMmBDXHnWPboUtuIJc6DwYEp1+9BhYaey6RGL+phfGmo5fOBpwyV0o+JCgsZf7yJMEZUXApbq9ApnriFYbKlGN7nQFGmoo6k/p35Xh0SydZadO4fNPSQDfFXRi/mC589IwFjbiO0utQXtQwbz0/1uxjeFxVWFSmiSXZ5fEfX3z+kxGSyu3qbHaBmaNV8L24lYGaXFN1I/vWHfmug831oo1W230I314rXUl9CEXojPX1ugRaDMr8OZzeZS9IuTMVQD3wfDV363y6EnRN7oVszr76E0ojc62jtQ8sg3MTeV3Y0jxPxKMyBLLjCCtxYV1hIfd70459f58E6b8p/4Yu0w3AjrxPX+Fi4ECFncY419YVCoVAoFAqFvfIP3kh1EJruRmEAAAAASUVORK5CYII=\" alt=\"a(2) = 3\" style=\"width: 56px; height: 18.5px;\" width=\"56\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 256px 8px; transform-origin: 256px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position (i.e., 4) to get 2, 3, 5, 6, 7, 8, 9,…In the third step, delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAlCAYAAACao20PAAADG0lEQVR4nO2a4bGrIBCFvx7swAZswApSQTqwg3RgC9aQEuwhLaSGtHDfD9mRKMiK+NQMZ4aZzEQQWPbs2UXIyMjIyMjI2BsF0CQcrwaqhONlLKAAetJueAE8gXvCMTMcKIAXeuPVphUrxv4FIxaMa5+2G9AeNbEeeASeqRi86W/SeqAM9C2AN9en0wfz9dutPmpS78AzFfAxzz1MezFO/EPYGxvT56ooGNbpM15/5KSW6E2ecYmbO+MCQh4M4wG4IuSga8LGf4PG+x4sK9M3gwGfyvd9dFM7HT4cGON80EwqlFb0DAbULK40z15N0AjTNJwojt8YJnXbOI54oHZhb3TeeibIGu2Y37GTMSvmEr9mrhRbM5ktnF6j9z7Bk2vRqB3nXa0jQVwsGOPL0/zuGY3k8hChvliIMl0rSkSKh1IP3zt9ediathal6dfgT6WijVjhprGCb5ef4kOc9C2Z50Mt+gVI35iNlEO3paXw/pK5IaPUtXiBLwbZbu76b60B76aPnQOuPYVCuzFCpjXv2dJSxl+bXjW58Bds47k2w/ZA1/9bk0+hbduImkK4GPCq+eAUdphaxSriBb7qhqhMn1BJVT2w36MZ79cMKKmR9gAD367rSwM6lg2csvwjh0kTX1KlL2eCrF9tQBEtviqKfSp8Ev9NOgMKlWoMuEXEHKVCQxBxpYrrFWHjdIR5eWsaYUOMoi2nxeafZ1GhU4gHqlKjxpqMi4Zqvifs26gt+dgUcmA0tNgTrr/6cDYVCiPbqW9abOU33TBRppKjyKB35vwsnrw1FslthTaNkDLUVSC07YMcXjU126rPptCaYXPsxL5lMJ7vGuRNeDOFHlwXt3Lbrr2sFXY45OIzAjbbudYoYnK1oraLqy/TxHjwzfdLd1hSflvynGkhtzP9WvPfmipMRzx9HoFpOLLXL6EgisEKxnjg+mioMf81LG+u5kK3ZB57HqbPGiEi77pa+rC0/lPgRkQZKAKyCRk7oGNfYSHx+VSfI/waevahhV/5Iu0S6EhrxD0+Fs4IIKXI0H78m5GRkZGRkZGRcTb8A/oNdpREGA/GAAAAAElFTkSuQmCC\" alt=\"a(3) = 5\" style=\"width: 56px; height: 18.5px;\" width=\"56\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 52.7167px 8px; transform-origin: 52.7167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position (i.e., 7) to get 2, 3, 5, 6, 8, 9, 10,…Et cetera.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 102px 8px; transform-origin: 102px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that returns the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 178.5px 8px; transform-origin: 178.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth term in the sequence after an infinite number of steps.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = goldenSieve(n)\r\n  y = f(n);\r\nend","test_suite":"%%\r\nn = 6; \r\ny_correct = 10;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 16; \r\ny_correct = 26;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 60; \r\ny_correct = 97;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 616; \r\ny_correct = 997;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 1666; \r\ny_correct = 2696;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 6066; \r\ny_correct = 9815;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 16166; \r\ny_correct = 26157;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 66616; \r\ny_correct = 107787;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 166666; \r\ny_correct = 269671;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 606606; \r\ny_correct = 981509;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 161161616; \r\ny_correct = 260764972;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 6161161616; \r\ny_correct = 9968968905;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 616161161616; \r\ny_correct = 996969702042;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2021-03-12T02:43:21.000Z","updated_at":"2025-12-17T13:39:40.000Z","published_at":"2021-03-12T02:52:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/45367\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCody Problem 45367\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involved the Sieve of Eratosthenes, and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/50811-compute-the-nth-term-from-the-sieve-of-flavius-josephus\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCody Problem 50811\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involved the Sieve of Flavius Josephus. To apply the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003egolden sieve\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, start with the natural numbers and at the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth step, take the sequence, which we will call \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e, and delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a(n)\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(n)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn the first step, delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(1) = 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position to get 2, 3, 4, 5, 6, 7,…Then in the second step, delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a(2) = 3\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(2) = 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position (i.e., 4) to get 2, 3, 5, 6, 7, 8, 9,…In the third step, delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a(3) = 5\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(3) = 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position (i.e., 7) to get 2, 3, 5, 6, 8, 9, 10,…Et cetera.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that returns the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth term in the sequence after an infinite number of steps.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":50811,"title":"Compute the nth term from the Sieve of Flavius Josephus","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 165px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 82.5px; transform-origin: 407px 82.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 381.5px 8px; transform-origin: 381.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTo apply the Sieve of Eratosthenes, start with the natural numbers (skipping 1), keep the first number (i.e., 2), and delete all multiples (4, 6, 8, 10, etc.). Then repeat: keep the first remaining number (3) and delete all multiples (9, 15, 21, etc.). The remaining numbers are the primes. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 247.5px 8px; transform-origin: 247.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTo apply the Sieve of Flavius Josephus, start with the natural numbers. On the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ek\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth step, remove every \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFwAAAAlCAYAAADPwo5RAAACbElEQVRoge2ZbZHCMBCGHw91gAEMVEEV4AAHdYAFNCChHrCAhlrgfqRLcz2gu/ng0rs8Mx1mICWbN9vdzRYqlUql8l9ogONvG1EQB5wmWWiAAdjnmmCD7MmkSQNcFX/cAC3uKbiQcfc/hEbIPXBTjlUzAP2b3xvgjNuU+3RdUxrwYQ44ES/K8S1uvUkcrJ8m17BjFvyUYvIP0+HWKmvQCs40NnrNDTDidlxDy2xsGzv5hznhQuGRMMHF2aLWbfFuGS/G5kLmsIhhJURwcKE3yq4R22My4AwdYiZdoWTBD9N9u5BJu+nmznCPGPouwcZSsuASVoLOKqfpZm3mlQ3KHb9LFhxcVAiyTcKDFtmg0fvuME3ue35svVq64AO2vPdgxBaLpQZfGimJNyiuPWELggcVDZbk1zAb6ccv8fCUlC642Gd2MIvgkp3vzCHjSFjylPbAq+vs2fZuXMwTlUJwcx6zCC4ijMzH/NBKxT88xVwxXc3iBZfj8IU5locuWDpwry6Za1wZZylnl8QIbq3uHtzQCb7nu2eN0+ctZFIFpcfw4KSpvdHvPbTMO2w9NGnZguBBnVJttpU6W2pPv2OY44hfuuB3XA4zI6FizUslhPiT+IcdqVoaAg1ZULLgopm2u/qDG+9F8iuK7sX3A07sS4whHiUL3jNXakGs/YHfjl2O8WO55e2Jxqacgvtrsp6Q1xx0lbUXECecB79q4fasv56zkktwORU/KzE1PaAWp1V0C6Mj8jFJTIsTIEV4SsmVhI51Jk3C+6vIk5yUgfK8qgSSvrFfcqaK7iNtiKzhNsfpcatULSqVSqVSycUXm/MeGpHoq6sAAAAASUVORK5CYII=\" alt=\"(k+1)\" style=\"width: 46px; height: 18.5px;\" width=\"46\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 23.5px 8px; transform-origin: 23.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003est term remaining after the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFwAAAAlCAYAAADPwo5RAAACUUlEQVRoge2aa5HCMBRGj4c6WAM1UAVVgAMc1AEW0ICEesACGmqB/ZFcGtiFJvf2lSFnprMzbEKSL8l9FSgUCoXCt1ABx60nsSMOOE0WoQJ6oF5qgAypWUiTCrhGfHEFNLhbcGHB3V+JGCFr4BbZNpoe6D78vwLOuE25++c65wRW5oAT8RLZvsGtd5YD1vnBY/hhFPw0x+Ar0+LWKmuIFRzf1rzmChhwOx5DwzjZxjr4ypxwpvCITnA5bKZ1p5xuaS+TzRmN4OBMb2qfJwbSrkmPm2hvGXQHaAU/+H4/mkFb37lN6CMT/eRgc0AruJgVVa5y8p1jPa9sUI72+xWt4OCsgsqsiHmIRTZoCD47+MHDk59D4mQRvCfN7z0YSLPFEoO/TlIcr8qubYRVcFXQkOL8KsZJhvZLTnhuWASXSC35gKUILt75zmgyjuidZ43zA5bHkvXNIXiyH0sR/MxovyXNt0Qqci0tj8VX7F5wSYcvjLbcUsY9+bEtj8VnWARPje4e3IgTvOb5ZA3+700z6E7YxGnGdgxrDw3jDqcmTXvCKriqUhrrbSXOltgzrBjmmuJbBL/jfFgyYiqmTqmYkHCQMNkR51WhnMgGaAUXzWKrq3+48VmksBzbvvm8x4l9sUxkZbSCd4yRmoqpLwjLsa9tQlue8vZka8I1pWbIUwd0kqkXEBK+vSvhdky/ntsLkhX/F2LG1IAanFbmEkaL8Zp8CVdmPFhn8nF4WyA3eVZ68nF6azLrG/tXzhTRQ+SHQIua21yzxyUoWhQKhUKhsBS/IqD7vWB5nPkAAAAASUVORK5CYII=\" alt=\"(k-1)\" style=\"width: 46px; height: 18.5px;\" width=\"46\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 296px 8px; transform-origin: 296px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003est step. So, on the first step, remove every second number (2, 4, 6, 8, etc.) to leave 1, 3, 5, 7, 9, 11, 13, 15, 17…On the second step, remove every third number (5, 11, 17, etc.) to leave 1, 3, 7, 9, 13, 15, 19,… \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 100.5px 8px; transform-origin: 100.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 254px 8px; transform-origin: 254px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth term in the sequence remaining after the Sieve of Flavius Josephus is applied.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = FlaviusJosephus(n)\r\n  y = f(n);\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = 7;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 7;\r\ny_correct = 39;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 53;\r\ny_correct = 2187;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 923;\r\ny_correct = 669121;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 1967;\r\ny_correct = 3039399;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 3449;\r\ny_correct = 9340303;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 6141;\r\ny_correct = 29614789;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 9460;\r\ny_correct = 70290691;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 23403;\r\ny_correct = 430160191;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 27182818;\r\ny_correct = 580335113880043;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n    \r\n%%\r\nn = 67;\r\ny_correct = 9781407;\r\nassert(isequal(FlaviusJosephus(FlaviusJosephus(n)),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2021-03-09T03:38:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2021-03-09T02:19:47.000Z","updated_at":"2025-12-17T13:21:36.000Z","published_at":"2021-03-09T02:40:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo apply the Sieve of Eratosthenes, start with the natural numbers (skipping 1), keep the first number (i.e., 2), and delete all multiples (4, 6, 8, 10, etc.). Then repeat: keep the first remaining number (3) and delete all multiples (9, 15, 21, etc.). The remaining numbers are the primes. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo apply the Sieve of Flavius Josephus, start with the natural numbers. On the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"k\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ek\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth step, remove every \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"(k+1)\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e(k+1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003est term remaining after the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"(k-1)\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e(k-1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003est step. So, on the first step, remove every second number (2, 4, 6, 8, etc.) to leave 1, 3, 5, 7, 9, 11, 13, 15, 17…On the second step, remove every third number (5, 11, 17, etc.) to leave 1, 3, 7, 9, 13, 15, 19,… \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to compute the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth term in the sequence remaining after the Sieve of Flavius Josephus is applied.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60990,"title":"Find the Prime Factors and Divisors of a Number","description":"Given a positive integer n, find its prime factors as well as all of its divisors.\r\nExample: n=12 has prime factors [2,2,3] and divisors [1,2,3,4,6,12].\r\nThe challenge is to do so without using built-in algorithims. Banned functions include primes(), isprime(), and factor(). See the last test case for other banned functions.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 102px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408.5px 51px; transform-origin: 408.5px 51px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385.5px 10.5px; text-align: left; transform-origin: 385.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a positive integer n, find its prime factors as well as all of its divisors.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385.5px 10.5px; text-align: left; transform-origin: 385.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample: n=12 has prime factors [2,2,3] and divisors \u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 0.727273px; border-bottom-style: solid; border-bottom-width: 0.727273px; \"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e1,2,3,4,6,12\u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 0.727273px; border-bottom-style: solid; border-bottom-width: 0.727273px; \"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385.5px 21px; text-align: left; transform-origin: 385.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe challenge is to do so without using built-in algorithims. Banned functions include primes(), isprime(), and factor(). See the last test case for other banned functions.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [PF,D] = FacDiv(n)\r\n    PF=[];\r\n    D=[];\r\nend","test_suite":"%%\r\nn=1;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[];\r\nD_correct=[1];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=12;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,3];\r\nD_correct=[1,2,3,4,6,12];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=360;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,2,3,3,5];\r\nD_correct=[1,2,3,4,5,6,8,9,10,12,15,18,20,24,30,36,40,45,60,72,90,120,180,360];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=2310;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,3,5,7,11];\r\nD_correct=[1,2,3,5,6,7,10,11,14,15,21,22,30,33,35,42,55,66,70,77,105,110,154,165,210,231,330,385,462,770,1155,2310];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=510510;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,3,5,7,11,13,17];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),128) \u0026\u0026 isequal(sum(D),1741824))\r\n\r\n%%\r\nn=2162160;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,2,2,3,3,3,5,7,11,13];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),320) \u0026\u0026 isequal(sum(D),9999360))\r\n\r\n%%\r\nn=954211441;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[954211441];\r\nD_correct=[1,954211441];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=200560490130;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,3,5,7,11,13,17,19,23,29,31];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),2048) \u0026\u0026 isequal(sum(D),802632499200))\r\n\r\n%%\r\nn=130429015516800;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,2,2,2,2,2,3,3,3,5,5,7,7,11,13,17,19,23,29];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),18432) \u0026\u0026 isequal(sum(D),784839767040000))\r\n\r\n%%\r\nfiletext=fileread('FacDiv.m');\r\nassert(~contains(filetext, 'regexp'))\r\nassert(~contains(filetext, 'assignin'))\r\nassert(~contains(filetext, 'echo'))\r\nassert(~contains(filetext, 'factor'))\r\nassert(~contains(filetext, 'primes'))\r\nassert(~contains(filetext, 'isprime'))\r\nassert(~contains(filetext, 'nthprime'))\r\nassert(~contains(filetext, 'nextprime'))\r\nassert(~contains(filetext, 'prevprime'))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4910069,"edited_by":4910069,"edited_at":"2025-08-03T03:36:37.000Z","deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-08-03T00:49:23.000Z","updated_at":"2026-03-09T11:33:48.000Z","published_at":"2025-08-03T03:36:37.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer n, find its prime factors as well as all of its divisors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: n=12 has prime factors [2,2,3] and divisors [1,2,3,4,6,12].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe challenge is to do so without using built-in algorithims. Banned functions include primes(), isprime(), and factor(). See the last test case for other banned functions.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60764,"title":"Determine whether a number is a Ludic prime","description":"Ludic numbers are formed by a sieve. Start with a list of the positive integers. Skip 1 and start with 2. Then delete every second number after 2 (i.e., 4, 6, 8, 10, etc.). Then move to the next number after 2—i.e., 3—and delete every third number (9, 15, 21, etc.). The next number is 5, so delete every fifth number (19, 37, etc.). Unlike the Sieve of Eratosthenes, this remaining numbers are not all prime. \r\nWrite a function to determine whether a number is a Ludic prime. The function should return three logical variables that answer these questions: Is it a Ludic prime? Is it a Ludic number? Is it prime? ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 135px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 67.5px; transform-origin: 407px 67.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 42px; text-align: left; transform-origin: 384px 42px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLudic numbers are formed by a sieve. Start with a list of the positive integers. Skip 1 and start with 2. Then delete every second number after 2 (i.e., 4, 6, 8, 10, etc.). Then move to the next number after 2—i.e., 3—and delete every third number (9, 15, 21, etc.). The next number is 5, so delete every fifth number (19, 37, etc.). Unlike the Sieve of Eratosthenes, this remaining numbers are not all prime. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine whether a number is a Ludic prime. The function should return three logical variables that answer these questions: Is it a Ludic prime? Is it a Ludic number? Is it prime? \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [tfLP, tfL, tfP] = isLudicPrime(n)\r\n%  tfLP   Is n a Ludic prime?\r\n%  tfL    Is n a Ludic number?\r\n%  tfP    Is n prime? \r\n  y = mod(n,2) \u0026\u0026 isprime(n);\r\nend","test_suite":"%%\r\nn = 1; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 2; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 3; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 5; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 19; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 43; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 101; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 835; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 1207; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 6353; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 10204; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 33943; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 105193; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 492135; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 1124081; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 1461809; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nN = 1600000 + [33 37 51 61 69 97 99 121 153];\r\nn = N(randi(length(N)));\r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nd = num2str(n)-'0'; \r\nif d(end)==1\r\n    assert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\nelse\r\n    assert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\nend\r\n\r\n%%\r\nn = 1700021; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nfiletext = fileread('isLudicPrime.m');\r\nillegal = contains(filetext, 'oeis') || contains(filetext, 'read') || contains(filetext, 'persistent');\r\nassert(~illegal)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2024-11-23T15:57:21.000Z","deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-11-23T15:57:08.000Z","updated_at":"2025-07-30T17:52:45.000Z","published_at":"2024-11-23T15:57:21.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLudic numbers are formed by a sieve. Start with a list of the positive integers. Skip 1 and start with 2. Then delete every second number after 2 (i.e., 4, 6, 8, 10, etc.). Then move to the next number after 2—i.e., 3—and delete every third number (9, 15, 21, etc.). The next number is 5, so delete every fifth number (19, 37, etc.). Unlike the Sieve of Eratosthenes, this remaining numbers are not all prime. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine whether a number is a Ludic prime. The function should return three logical variables that answer these questions: Is it a Ludic prime? Is it a Ludic number? Is it prime? \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":61146,"title":"Extract numbers using a decaying sieve","description":"The Sieve of Eratosthenes is one method of determining primes. Starting with 2, one keeps 2 and removes 2x2, 3x2, 4x2, etc. Then the next remaining number is 3, and one keeps 3 and removes 2x3 (already removed), 3x3, 4x3 (already removed), etc. The sieving continues with multiples of 5, 7, 11, etc.\r\nThis problem involves a decaying sieve. In the Sieve of Eratosthenes, the gaps between the sieved numbers is constant at each step: if the next remaining number is 5 (say), then the gap is 5 as well, and the numbers removed are 10, 15, 20, 25, etc. In the decaying sieve, the gap decreases by 1 between numbers: if the next remaining number is 4, then the gaps are 3, 2, 1 so that the numbers removed are 7, 9, and 10. Notice that the decaying sieve removes a finite number of elements. \r\nThe sieve starts like this:\r\nThe first remaining number is 1. Keep 1. Because 1-1 = 0, no numbers are removed.\r\nThe next remaining number is 2. Keep 2 and remove 2+1 = 3.\r\nThe next remaining number is 4. Keep 4 and remove 4+3 = 7, 4+3+2 = 9, and 4+3+2+1 = 10.\r\nEt cetera \r\nWrite a function to apply the decaying sieve to numbers from 1 to the input number.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 318.75px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 408px 159.375px; transform-origin: 408px 159.375px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe Sieve of Eratosthenes is one method of determining primes. Starting with 2, one keeps 2 and removes 2x2, 3x2, 4x2, etc. Then the next remaining number is 3, and one keeps 3 and removes 2x3 (already removed), 3x3, 4x3 (already removed), etc. The sieving continues with multiples of 5, 7, 11, etc.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 84px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 42px; text-align: left; transform-origin: 384px 42px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem involves a decaying sieve. In the Sieve of Eratosthenes, the gaps between the sieved numbers is constant at each step: if the next remaining number is 5 (say), then the gap is 5 as well, and the numbers removed are 10, 15, 20, 25, etc. In the decaying sieve, the gap decreases by 1 between numbers: if the next remaining number is 4, then the gaps are 3, 2, 1 so that the numbers removed are 7, 9, and 10. Notice that the decaying sieve removes a finite number of elements. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe sieve starts like this:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 81.75px; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 391px 40.875px; transform-origin: 391px 40.875px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe first remaining number is 1. Keep 1. Because 1-1 = 0, no numbers are removed.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe next remaining number is 2. Keep 2 and remove 2+1 = 3.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe next remaining number is 4. Keep 4 and remove 4+3 = 7, 4+3+2 = 9, and 4+3+2+1 = 10.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEt cetera \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to apply the decaying sieve to numbers from 1 to the input number.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = decayingSieve(N)\r\n  y = 1:N;\r\nend","test_suite":"%%\r\nN = 20;\r\ny = decayingSieve(N);\r\ny_correct = [1 2 4 5 6 8 13 16 17 19];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nN = 100;\r\ny = decayingSieve(N);\r\ny_correct = [1 2 4 5 6 8 13 16 17 19 22 23 24 27 28 29 32 34 38 39 40 41 42 44 49 50 51 52 56 59 60 61 64 65 68 71 72 73 74 80 89 92 94 95 96];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nN = 1000;\r\ny = decayingSieve(N);\r\nlen_correct = 347;\r\nsum_correct = 167668;\r\nassert(isequal(length(y),len_correct))\r\nassert(isequal(sum(y),sum_correct))\r\n\r\n%%\r\nN = 15707;\r\ny = decayingSieve(N);\r\nlen_correct = 5000;\r\nsum_correct = 37983865;\r\nassert(isequal(length(y),len_correct))\r\nassert(isequal(sum(y),sum_correct))\r\n\r\n%%\r\nN = 200000;\r\ny = decayingSieve(N);\r\nlen_correct = 56635;\r\nsum_correct = 5563986488;\r\nlenp_correct = 14143;\r\nassert(isequal(length(y),len_correct))\r\nassert(isequal(sum(y),sum_correct))\r\nassert(isequal(length(y(isprime(y))),lenp_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2026-01-02T16:14:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2026-01-02T16:11:28.000Z","updated_at":"2026-02-26T10:21:53.000Z","published_at":"2026-01-02T16:11:28.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Sieve of Eratosthenes is one method of determining primes. Starting with 2, one keeps 2 and removes 2x2, 3x2, 4x2, etc. Then the next remaining number is 3, and one keeps 3 and removes 2x3 (already removed), 3x3, 4x3 (already removed), etc. The sieving continues with multiples of 5, 7, 11, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem involves a decaying sieve. In the Sieve of Eratosthenes, the gaps between the sieved numbers is constant at each step: if the next remaining number is 5 (say), then the gap is 5 as well, and the numbers removed are 10, 15, 20, 25, etc. In the decaying sieve, the gap decreases by 1 between numbers: if the next remaining number is 4, then the gaps are 3, 2, 1 so that the numbers removed are 7, 9, and 10. Notice that the decaying sieve removes a finite number of elements. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe sieve starts like this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first remaining number is 1. Keep 1. Because 1-1 = 0, no numbers are removed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe next remaining number is 2. Keep 2 and remove 2+1 = 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe next remaining number is 4. Keep 4 and remove 4+3 = 7, 4+3+2 = 9, and 4+3+2+1 = 10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEt cetera \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to apply the decaying sieve to numbers from 1 to the input number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60411,"title":"Compute a sequence with the whyphi sieve","description":"A few problems on Cody involve sieving. For example, Cody Problem 45367 involves the famous Sieve of Eratosthenes. CP 50811 uses the sieve of Flavius Josephus, and CP 50913 uses the golden sieve. \r\nThis problem uses a process that I will call the whyphi sieve: \r\nMake a list x of integers 1, 2, 3,… \r\nRemove the first term. That is, delete x(1).\r\nRenumber the terms. \r\nDelete x(2) and x(2+1)\r\nRenumber the terms. \r\nDelete x(3), x(3+2), and x(3+2+1). \r\nContinue renumbering and deleting terms in this way. \r\nWrite a function to compute the nth term of this sequence. ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 266.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 133.017px; transform-origin: 407px 133.017px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 170.375px 7.79167px; transform-origin: 170.375px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA few problems on Cody involve sieving. For example, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/45367\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eCody Problem 45367\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 138.075px 7.79167px; transform-origin: 138.075px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involves the famous Sieve of Eratosthenes. \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/50811\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eCP 50811\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 127.967px 7.79167px; transform-origin: 127.967px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e uses the sieve of Flavius Josephus, and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/50913\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eCP 50913\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 73.5167px 7.79167px; transform-origin: 73.5167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e uses the golden sieve. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 188.65px 7.79167px; transform-origin: 188.65px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem uses a process that I will call the whyphi sieve: \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 143.033px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 71.5167px; transform-origin: 391px 71.5167px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 105.775px 7.79167px; transform-origin: 105.775px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eMake a list x of integers 1, 2, 3,… \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 130.667px 7.79167px; transform-origin: 130.667px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRemove the first term. That is, delete x(1).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 67.675px 7.79167px; transform-origin: 67.675px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRenumber the terms. \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 69.8333px 7.79167px; transform-origin: 69.8333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDelete x(2) and x(2+1)\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 67.675px 7.79167px; transform-origin: 67.675px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRenumber the terms. \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 107.567px 7.79167px; transform-origin: 107.567px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDelete x(3), x(3+2), and x(3+2+1). \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 166.758px 7.79167px; transform-origin: 166.758px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eContinue renumbering and deleting terms in this way. \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 181.108px 7.79167px; transform-origin: 181.108px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the nth term of this sequence. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = whyphiSieve(n)\r\n  c = 100*[0.000057513128234 0.093378634167431 -2.856145294974328]\r\n  y = polyval(c,n);\r\nend","test_suite":"%%\r\nassert(isequal(whyphiSieve(1),2))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(5),14))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(19),79))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(54),305))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(89),594))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(135),1032))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(336),3443))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(689),8948))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(1000),14685))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(4509),109040))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(whyphiSieve(428)),116991))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(whyphiSieve(620)),225368))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(10000),315192))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(20000),793960))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2024-06-04T15:38:44.000Z","deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-05-28T02:46:53.000Z","updated_at":"2026-03-30T07:39:19.000Z","published_at":"2024-05-28T02:47:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA few problems on Cody involve sieving. For example, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/45367\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCody Problem 45367\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involves the famous Sieve of Eratosthenes. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/50811\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCP 50811\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e uses the sieve of Flavius Josephus, and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/50913\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCP 50913\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e uses the golden sieve. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem uses a process that I will call the whyphi sieve: \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMake a list x of integers 1, 2, 3,… \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRemove the first term. That is, delete x(1).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRenumber the terms. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDelete x(2) and x(2+1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRenumber the terms. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDelete x(3), x(3+2), and x(3+2+1). \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eContinue renumbering and deleting terms in this way. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to compute the nth term of this sequence. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":50913,"title":"Compute the nth term from the golden sieve","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 165px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 82.5px; transform-origin: 407px 82.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/45367\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003eCody Problem 45367\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 129.5px 8px; transform-origin: 129.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved the Sieve of Eratosthenes, and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/50811-compute-the-nth-term-from-the-sieve-of-flavius-josephus\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003eCody Problem 50811\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 94px 8px; transform-origin: 94px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involved the Sieve of Flavius Josephus. To apply the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 39.5px 8px; transform-origin: 39.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003egolden sieve\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 133.5px 8px; transform-origin: 133.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, start with the natural numbers and at the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 129px 8px; transform-origin: 129px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth step, take the sequence, which we will call \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ea\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 87px 8px; transform-origin: 87px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADsAAAAlCAYAAAD8+ZFYAAACUklEQVRoge2YXZWDMBCFPw9xUAMYQEEV1AEOcFALaKgEPNQCGrDAPpA5mdIJSbpA+8B92tOwM3PnP4ETJ06csOGAZkN5NVBtKG8zOKBnW+Mc8ABuG8r8NxzwZJ8oiOyfIdwD7Y7yHTDwAyndekP2RsMc4a/BASPHpdjAvhm0iqOiqvWNB+p7wQjcD9R3ASa+0KyuXvH1YL0D8zjaBBXzMHfqt5rZqxp3ZrKOMlwMWZbOGB78M5UdoR4e/u+eQGjive33/vcUGi9HvteyauZIye9P0oRb/+3SYVmolEJNyCkjLE+OnkCOfEn5idDQboRO/lDnqbIQsnWG7jdDRuzIoQzoImc5ZOHVcS0zoYEQxVadpyJW80GT0kStf9QGWuclZHVkr16vJiWRzVkahGzRvH0mFGgDrToqISu1P2LvuVJGOQSKyd5I10jHujNKyOomtCyJSp3l1GHxyBPlse1HhvdEfGkYyCOrZVlZ0hBvghaKGpT2ZIxIR9rbJaNHZFkXe6nX3EVByGbNd63cSoWa9Ugslaa6px4rsdov6a49Bfu4bvNLstKhl93xxntUJENStSO6rMjpJnghXNTXMGKPQhNagU7j2gvSS8admaieiRpDQrHOEityugkK0TXnibyihWK5oj0JRFFnI3GiEFbM2LleN61vJINET+qxruODK6Uj7KvWg1bjz5qIkVrO2uVddMQaYaVsSEVLdB19y3qBbESlt59SiOO+jo6CpvEBpJ/s7dBs9OzzgvAzL4tLdGxLeI+H902xZQPJfb04ceLEid/HH7ed5mf0eC3FAAAAAElFTkSuQmCC\" alt=\"a(n)\" style=\"width: 29.5px; height: 18.5px;\" width=\"29.5\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 30.5px 8px; transform-origin: 30.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 119.5px 8px; transform-origin: 119.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn the first step, delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAlCAYAAACao20PAAACgElEQVR4nO2abbGjMBRAj4c4WAMYQEEV4AAHdYAFNCABD7WABix0fyQZ8vqSlnywhO49M8y8eSUh5OTjXgAEQRAEQTgaBfQF62uBpmB9whsUMFO2wxUwAV3BOgUPCngQL2/P+bbub5RYzeoyA/eI81tTZt15vgIWKrrhTDr0/UxnNwS0uGXnuQ1a3NMcewWC3lsfcU2rjhu6r+z9ny5QoSXsWd56tOybKRMrEPTNx8z0mhjQfdBTkcCY2ediZ2GswHtCmRqpRuCKHlmxpAr8Y8pdPaCpQuDNNOKWUDZVIFS0+WdwqMAGHSUq538tevS7DKYRinhyBE6J5WqiuEDFtr9M5u+ZTdKT3yG8lZBCjsC7Kfs6oPZgB2fukUtRgQ1baOtKUrwP91e0iBRKCEzpSDeFST1KzP5iAhu2kN6XJNsLjYHfzhDYkh7IDObaOUeJWVNEoCvP1xnuDPT9frbAq+aDUEjgw1QSerpho8xQoCIC08kW2DmVhNKAkfeCzxKYk77UQrZAG7SEnqLYhPlJOFFfuF4Q8xVRaMNnOaNzTqjBZ6cROfnnpaNQ92Gqbxlq+dngUEfl5GM5AmfSnr/Cl0ShtuN9Am1kOvFz/+v4/amEncn/+lHaij+tuRJZAt3o0l1CW3TnuIn9wPby0TcTF9I6M1WgXR1K7ENnUiyIsbPswSbPvcBKWB5sj99i9qPXJTpGxkj68lkL7gq4kLYFodj2A99HQ735ree9nJgXui1agG9fGfi8FNtrXTV96NB97bv/Oyd+LmLfsKdEhTHYASccwMixgYXdn48eJP81M8e8Kf+2L9KqZqSsxCM+FhY+UDLIeP0yQBAEQRAEQbgKfwHdzFGGzPiz9wAAAABJRU5ErkJggg==\" style=\"width: 56px; height: 18.5px;\" width=\"56\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 231.5px 8px; transform-origin: 231.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position to get 2, 3, 4, 5, 6, 7,…Then in the second step, delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAlCAYAAACao20PAAADI0lEQVR4nO2a4Y2DMAxG3w5swAIswASdoBt0g27ACp2hI3SHW6EzdIXej2Dh0pCYEARUeRLS6QqB2LH9OQCFQqFQKBTWpgIuGcdrgSbjeIUAFfAgr8Er4A6cM45Z8FABf9icV+EiqwXqGWP/ihP1/HfDA7hGzmn6896j40l8MlV/3pHT6Qm3EMfz73Dz24wrzrghTnw/+Pg4Rca44AxwRM64OcpC73A2e6v/b0IFvAinNznnwWeknfiOyNhKfBKP9L3R4p7bt0BvDHPfJKVaoq/DRc6Uc7QTYwr2ilsMRyIk7Grsc1+FF85BsXNCtUun13tkLJnwUQRNRfxZrSUkO2L40I1rXJqIYXUguIi3nHcEZEE+yShkGlw+1gP6JH+HrW5ZEAda6tud46XRKa5kir6Kob7c+78fDE56850GpXYtRdcBS5sgk7b0kGNkcS49cnDG2Xux8xoGSasNWDEY1rfiRVkuRUtsC+LAFEP6+tC5x9Lob3BBosdLFjBNP8DU6peb+OpYrv5FjGpt0lvShUzX32/JsaT+yv11D6gb+llo5/mMoSPQ93sOB4oz5vR2KdfskZrPSJyziIFhW2dqd0PLe59QWepA2R6zqFTNrzhQ0DrDPCepOyEFJLsEUw5e6sB7f/1cFWtpX46EznTm9Cw5eGoXRSvDqdz8JN2BN9KcB8tEzJ5UqEZ0gMmBDXHnWPboUtuIJc6DwYEp1+9BhYaey6RGL+phfGmo5fOBpwyV0o+JCgsZf7yJMEZUXApbq9ApnriFYbKlGN7nQFGmoo6k/p35Xh0SydZadO4fNPSQDfFXRi/mC589IwFjbiO0utQXtQwbz0/1uxjeFxVWFSmiSXZ5fEfX3z+kxGSyu3qbHaBmaNV8L24lYGaXFN1I/vWHfmug831oo1W230I314rXUl9CEXojPX1ugRaDMr8OZzeZS9IuTMVQD3wfDV363y6EnRN7oVszr76E0ojc62jtQ8sg3MTeV3Y0jxPxKMyBLLjCCtxYV1hIfd70459f58E6b8p/4Yu0w3AjrxPX+Fi4ECFncY419YVCoVAoFAqFvfIP3kh1EJruRmEAAAAASUVORK5CYII=\" alt=\"a(2) = 3\" style=\"width: 56px; height: 18.5px;\" width=\"56\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 256px 8px; transform-origin: 256px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position (i.e., 4) to get 2, 3, 5, 6, 7, 8, 9,…In the third step, delete the term in the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAAlCAYAAACao20PAAADG0lEQVR4nO2a4bGrIBCFvx7swAZswApSQTqwg3RgC9aQEuwhLaSGtHDfD9mRKMiK+NQMZ4aZzEQQWPbs2UXIyMjIyMjI2BsF0CQcrwaqhONlLKAAetJueAE8gXvCMTMcKIAXeuPVphUrxv4FIxaMa5+2G9AeNbEeeASeqRi86W/SeqAM9C2AN9en0wfz9dutPmpS78AzFfAxzz1MezFO/EPYGxvT56ooGNbpM15/5KSW6E2ecYmbO+MCQh4M4wG4IuSga8LGf4PG+x4sK9M3gwGfyvd9dFM7HT4cGON80EwqlFb0DAbULK40z15N0AjTNJwojt8YJnXbOI54oHZhb3TeeibIGu2Y37GTMSvmEr9mrhRbM5ktnF6j9z7Bk2vRqB3nXa0jQVwsGOPL0/zuGY3k8hChvliIMl0rSkSKh1IP3zt9ediathal6dfgT6WijVjhprGCb5ef4kOc9C2Z50Mt+gVI35iNlEO3paXw/pK5IaPUtXiBLwbZbu76b60B76aPnQOuPYVCuzFCpjXv2dJSxl+bXjW58Bds47k2w/ZA1/9bk0+hbduImkK4GPCq+eAUdphaxSriBb7qhqhMn1BJVT2w36MZ79cMKKmR9gAD367rSwM6lg2csvwjh0kTX1KlL2eCrF9tQBEtviqKfSp8Ev9NOgMKlWoMuEXEHKVCQxBxpYrrFWHjdIR5eWsaYUOMoi2nxeafZ1GhU4gHqlKjxpqMi4Zqvifs26gt+dgUcmA0tNgTrr/6cDYVCiPbqW9abOU33TBRppKjyKB35vwsnrw1FslthTaNkDLUVSC07YMcXjU126rPptCaYXPsxL5lMJ7vGuRNeDOFHlwXt3Lbrr2sFXY45OIzAjbbudYoYnK1oraLqy/TxHjwzfdLd1hSflvynGkhtzP9WvPfmipMRzx9HoFpOLLXL6EgisEKxnjg+mioMf81LG+u5kK3ZB57HqbPGiEi77pa+rC0/lPgRkQZKAKyCRk7oGNfYSHx+VSfI/waevahhV/5Iu0S6EhrxD0+Fs4IIKXI0H78m5GRkZGRkZGRcTb8A/oNdpREGA/GAAAAAElFTkSuQmCC\" alt=\"a(3) = 5\" style=\"width: 56px; height: 18.5px;\" width=\"56\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 52.7167px 8px; transform-origin: 52.7167px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e position (i.e., 7) to get 2, 3, 5, 6, 8, 9, 10,…Et cetera.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 102px 8px; transform-origin: 102px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that returns the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 178.5px 8px; transform-origin: 178.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth term in the sequence after an infinite number of steps.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = goldenSieve(n)\r\n  y = f(n);\r\nend","test_suite":"%%\r\nn = 6; \r\ny_correct = 10;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 16; \r\ny_correct = 26;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 60; \r\ny_correct = 97;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 616; \r\ny_correct = 997;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 1666; \r\ny_correct = 2696;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 6066; \r\ny_correct = 9815;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 16166; \r\ny_correct = 26157;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 66616; \r\ny_correct = 107787;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 166666; \r\ny_correct = 269671;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 606606; \r\ny_correct = 981509;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 161161616; \r\ny_correct = 260764972;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 6161161616; \r\ny_correct = 9968968905;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nn = 616161161616; \r\ny_correct = 996969702042;\r\ny = goldenSieve(n);\r\nassert(isequal(y,y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2021-03-12T02:43:21.000Z","updated_at":"2025-12-17T13:39:40.000Z","published_at":"2021-03-12T02:52:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/45367\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCody Problem 45367\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involved the Sieve of Eratosthenes, and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/50811-compute-the-nth-term-from-the-sieve-of-flavius-josephus\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCody Problem 50811\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involved the Sieve of Flavius Josephus. To apply the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003egolden sieve\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, start with the natural numbers and at the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth step, take the sequence, which we will call \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e, and delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a(n)\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(n)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn the first step, delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(1) = 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position to get 2, 3, 4, 5, 6, 7,…Then in the second step, delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a(2) = 3\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(2) = 3\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position (i.e., 4) to get 2, 3, 5, 6, 7, 8, 9,…In the third step, delete the term in the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"a(3) = 5\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ea(3) = 5\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e position (i.e., 7) to get 2, 3, 5, 6, 8, 9, 10,…Et cetera.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function that returns the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth term in the sequence after an infinite number of steps.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":50811,"title":"Compute the nth term from the Sieve of Flavius Josephus","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 165px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 82.5px; transform-origin: 407px 82.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 381.5px 8px; transform-origin: 381.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTo apply the Sieve of Eratosthenes, start with the natural numbers (skipping 1), keep the first number (i.e., 2), and delete all multiples (4, 6, 8, 10, etc.). Then repeat: keep the first remaining number (3) and delete all multiples (9, 15, 21, etc.). The remaining numbers are the primes. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 247.5px 8px; transform-origin: 247.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTo apply the Sieve of Flavius Josephus, start with the natural numbers. On the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003ek\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 70.5px 8px; transform-origin: 70.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth step, remove every \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFwAAAAlCAYAAADPwo5RAAACbElEQVRoge2ZbZHCMBCGHw91gAEMVEEV4AAHdYAFNCChHrCAhlrgfqRLcz2gu/ng0rs8Mx1mICWbN9vdzRYqlUql8l9ogONvG1EQB5wmWWiAAdjnmmCD7MmkSQNcFX/cAC3uKbiQcfc/hEbIPXBTjlUzAP2b3xvgjNuU+3RdUxrwYQ44ES/K8S1uvUkcrJ8m17BjFvyUYvIP0+HWKmvQCs40NnrNDTDidlxDy2xsGzv5hznhQuGRMMHF2aLWbfFuGS/G5kLmsIhhJURwcKE3yq4R22My4AwdYiZdoWTBD9N9u5BJu+nmznCPGPouwcZSsuASVoLOKqfpZm3mlQ3KHb9LFhxcVAiyTcKDFtmg0fvuME3ue35svVq64AO2vPdgxBaLpQZfGimJNyiuPWELggcVDZbk1zAb6ccv8fCUlC642Gd2MIvgkp3vzCHjSFjylPbAq+vs2fZuXMwTlUJwcx6zCC4ijMzH/NBKxT88xVwxXc3iBZfj8IU5locuWDpwry6Za1wZZylnl8QIbq3uHtzQCb7nu2eN0+ctZFIFpcfw4KSpvdHvPbTMO2w9NGnZguBBnVJttpU6W2pPv2OY44hfuuB3XA4zI6FizUslhPiT+IcdqVoaAg1ZULLgopm2u/qDG+9F8iuK7sX3A07sS4whHiUL3jNXakGs/YHfjl2O8WO55e2Jxqacgvtrsp6Q1xx0lbUXECecB79q4fasv56zkktwORU/KzE1PaAWp1V0C6Mj8jFJTIsTIEV4SsmVhI51Jk3C+6vIk5yUgfK8qgSSvrFfcqaK7iNtiKzhNsfpcatULSqVSqVSycUXm/MeGpHoq6sAAAAASUVORK5CYII=\" alt=\"(k+1)\" style=\"width: 46px; height: 18.5px;\" width=\"46\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 23.5px 8px; transform-origin: 23.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003est term remaining after the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFwAAAAlCAYAAADPwo5RAAACUUlEQVRoge2aa5HCMBRGj4c6WAM1UAVVgAMc1AEW0ICEesACGmqB/ZFcGtiFJvf2lSFnprMzbEKSL8l9FSgUCoXCt1ABx60nsSMOOE0WoQJ6oF5qgAypWUiTCrhGfHEFNLhbcGHB3V+JGCFr4BbZNpoe6D78vwLOuE25++c65wRW5oAT8RLZvsGtd5YD1vnBY/hhFPw0x+Ar0+LWKmuIFRzf1rzmChhwOx5DwzjZxjr4ypxwpvCITnA5bKZ1p5xuaS+TzRmN4OBMb2qfJwbSrkmPm2hvGXQHaAU/+H4/mkFb37lN6CMT/eRgc0AruJgVVa5y8p1jPa9sUI72+xWt4OCsgsqsiHmIRTZoCD47+MHDk59D4mQRvCfN7z0YSLPFEoO/TlIcr8qubYRVcFXQkOL8KsZJhvZLTnhuWASXSC35gKUILt75zmgyjuidZ43zA5bHkvXNIXiyH0sR/MxovyXNt0Qqci0tj8VX7F5wSYcvjLbcUsY9+bEtj8VnWARPje4e3IgTvOb5ZA3+700z6E7YxGnGdgxrDw3jDqcmTXvCKriqUhrrbSXOltgzrBjmmuJbBL/jfFgyYiqmTqmYkHCQMNkR51WhnMgGaAUXzWKrq3+48VmksBzbvvm8x4l9sUxkZbSCd4yRmoqpLwjLsa9tQlue8vZka8I1pWbIUwd0kqkXEBK+vSvhdky/ntsLkhX/F2LG1IAanFbmEkaL8Zp8CVdmPFhn8nF4WyA3eVZ68nF6azLrG/tXzhTRQ+SHQIua21yzxyUoWhQKhUKhsBS/IqD7vWB5nPkAAAAASUVORK5CYII=\" alt=\"(k-1)\" style=\"width: 46px; height: 18.5px;\" width=\"46\" height=\"18.5\"\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 296px 8px; transform-origin: 296px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003est step. So, on the first step, remove every second number (2, 4, 6, 8, etc.) to leave 1, 3, 5, 7, 9, 11, 13, 15, 17…On the second step, remove every third number (5, 11, 17, etc.) to leave 1, 3, 7, 9, 13, 15, 19,… \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 100.5px 8px; transform-origin: 100.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 254px 8px; transform-origin: 254px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eth term in the sequence remaining after the Sieve of Flavius Josephus is applied.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = FlaviusJosephus(n)\r\n  y = f(n);\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = 7;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 7;\r\ny_correct = 39;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 53;\r\ny_correct = 2187;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 923;\r\ny_correct = 669121;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 1967;\r\ny_correct = 3039399;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 3449;\r\ny_correct = 9340303;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 6141;\r\ny_correct = 29614789;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 9460;\r\ny_correct = 70290691;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 23403;\r\ny_correct = 430160191;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n\r\n%%\r\nn = 27182818;\r\ny_correct = 580335113880043;\r\nassert(isequal(FlaviusJosephus(n),y_correct))\r\n    \r\n%%\r\nn = 67;\r\ny_correct = 9781407;\r\nassert(isequal(FlaviusJosephus(FlaviusJosephus(n)),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2021-03-09T03:38:44.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2021-03-09T02:19:47.000Z","updated_at":"2025-12-17T13:21:36.000Z","published_at":"2021-03-09T02:40:03.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo apply the Sieve of Eratosthenes, start with the natural numbers (skipping 1), keep the first number (i.e., 2), and delete all multiples (4, 6, 8, 10, etc.). Then repeat: keep the first remaining number (3) and delete all multiples (9, 15, 21, etc.). The remaining numbers are the primes. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo apply the Sieve of Flavius Josephus, start with the natural numbers. On the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"k\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ek\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth step, remove every \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"(k+1)\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e(k+1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003est term remaining after the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"(k-1)\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e(k-1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003est step. So, on the first step, remove every second number (2, 4, 6, 8, etc.) to leave 1, 3, 5, 7, 9, 11, 13, 15, 17…On the second step, remove every third number (5, 11, 17, etc.) to leave 1, 3, 7, 9, 13, 15, 19,… \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to compute the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003eth term in the sequence remaining after the Sieve of Flavius Josephus is applied.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60990,"title":"Find the Prime Factors and Divisors of a Number","description":"Given a positive integer n, find its prime factors as well as all of its divisors.\r\nExample: n=12 has prime factors [2,2,3] and divisors [1,2,3,4,6,12].\r\nThe challenge is to do so without using built-in algorithims. Banned functions include primes(), isprime(), and factor(). See the last test case for other banned functions.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 102px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408.5px 51px; transform-origin: 408.5px 51px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385.5px 10.5px; text-align: left; transform-origin: 385.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a positive integer n, find its prime factors as well as all of its divisors.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385.5px 10.5px; text-align: left; transform-origin: 385.5px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample: n=12 has prime factors [2,2,3] and divisors \u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 0.727273px; border-bottom-style: solid; border-bottom-width: 0.727273px; \"\u003e[\u003c/span\u003e\u003cspan style=\"\"\u003e1,2,3,4,6,12\u003c/span\u003e\u003cspan style=\"border-block-end-style: solid; border-block-end-width: 0.727273px; border-bottom-style: solid; border-bottom-width: 0.727273px; \"\u003e]\u003c/span\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385.5px 21px; text-align: left; transform-origin: 385.5px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe challenge is to do so without using built-in algorithims. Banned functions include primes(), isprime(), and factor(). See the last test case for other banned functions.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [PF,D] = FacDiv(n)\r\n    PF=[];\r\n    D=[];\r\nend","test_suite":"%%\r\nn=1;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[];\r\nD_correct=[1];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=12;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,3];\r\nD_correct=[1,2,3,4,6,12];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=360;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,2,3,3,5];\r\nD_correct=[1,2,3,4,5,6,8,9,10,12,15,18,20,24,30,36,40,45,60,72,90,120,180,360];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=2310;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,3,5,7,11];\r\nD_correct=[1,2,3,5,6,7,10,11,14,15,21,22,30,33,35,42,55,66,70,77,105,110,154,165,210,231,330,385,462,770,1155,2310];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=510510;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,3,5,7,11,13,17];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),128) \u0026\u0026 isequal(sum(D),1741824))\r\n\r\n%%\r\nn=2162160;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,2,2,3,3,3,5,7,11,13];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),320) \u0026\u0026 isequal(sum(D),9999360))\r\n\r\n%%\r\nn=954211441;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[954211441];\r\nD_correct=[1,954211441];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(D,D_correct))\r\n\r\n%%\r\nn=200560490130;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,3,5,7,11,13,17,19,23,29,31];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),2048) \u0026\u0026 isequal(sum(D),802632499200))\r\n\r\n%%\r\nn=130429015516800;\r\n[PF,D]=FacDiv(n);\r\nPF_correct=[2,2,2,2,2,2,2,3,3,3,5,5,7,7,11,13,17,19,23,29];\r\nassert(isequal(PF,PF_correct) \u0026\u0026 isequal(length(D),18432) \u0026\u0026 isequal(sum(D),784839767040000))\r\n\r\n%%\r\nfiletext=fileread('FacDiv.m');\r\nassert(~contains(filetext, 'regexp'))\r\nassert(~contains(filetext, 'assignin'))\r\nassert(~contains(filetext, 'echo'))\r\nassert(~contains(filetext, 'factor'))\r\nassert(~contains(filetext, 'primes'))\r\nassert(~contains(filetext, 'isprime'))\r\nassert(~contains(filetext, 'nthprime'))\r\nassert(~contains(filetext, 'nextprime'))\r\nassert(~contains(filetext, 'prevprime'))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4910069,"edited_by":4910069,"edited_at":"2025-08-03T03:36:37.000Z","deleted_by":null,"deleted_at":null,"solvers_count":8,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-08-03T00:49:23.000Z","updated_at":"2026-03-09T11:33:48.000Z","published_at":"2025-08-03T03:36:37.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a positive integer n, find its prime factors as well as all of its divisors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: n=12 has prime factors [2,2,3] and divisors [1,2,3,4,6,12].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe challenge is to do so without using built-in algorithims. Banned functions include primes(), isprime(), and factor(). See the last test case for other banned functions.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60764,"title":"Determine whether a number is a Ludic prime","description":"Ludic numbers are formed by a sieve. Start with a list of the positive integers. Skip 1 and start with 2. Then delete every second number after 2 (i.e., 4, 6, 8, 10, etc.). Then move to the next number after 2—i.e., 3—and delete every third number (9, 15, 21, etc.). The next number is 5, so delete every fifth number (19, 37, etc.). Unlike the Sieve of Eratosthenes, this remaining numbers are not all prime. \r\nWrite a function to determine whether a number is a Ludic prime. The function should return three logical variables that answer these questions: Is it a Ludic prime? Is it a Ludic number? Is it prime? ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 135px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 67.5px; transform-origin: 407px 67.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 42px; text-align: left; transform-origin: 384px 42px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLudic numbers are formed by a sieve. Start with a list of the positive integers. Skip 1 and start with 2. Then delete every second number after 2 (i.e., 4, 6, 8, 10, etc.). Then move to the next number after 2—i.e., 3—and delete every third number (9, 15, 21, etc.). The next number is 5, so delete every fifth number (19, 37, etc.). Unlike the Sieve of Eratosthenes, this remaining numbers are not all prime. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to determine whether a number is a Ludic prime. The function should return three logical variables that answer these questions: Is it a Ludic prime? Is it a Ludic number? Is it prime? \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [tfLP, tfL, tfP] = isLudicPrime(n)\r\n%  tfLP   Is n a Ludic prime?\r\n%  tfL    Is n a Ludic number?\r\n%  tfP    Is n prime? \r\n  y = mod(n,2) \u0026\u0026 isprime(n);\r\nend","test_suite":"%%\r\nn = 1; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 2; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 3; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 5; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 19; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 43; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 101; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 835; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 1207; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 6353; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nn = 10204; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 33943; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 105193; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 492135; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 1124081; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 tfL \u0026\u0026 ~tfP)\r\n\r\n%%\r\nn = 1461809; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nN = 1600000 + [33 37 51 61 69 97 99 121 153];\r\nn = N(randi(length(N)));\r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nd = num2str(n)-'0'; \r\nif d(end)==1\r\n    assert(tfLP \u0026\u0026 tfL \u0026\u0026 tfP)\r\nelse\r\n    assert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\nend\r\n\r\n%%\r\nn = 1700021; \r\n[tfLP, tfL, tfP] = isLudicPrime(n);\r\nassert(~tfLP \u0026\u0026 ~tfL \u0026\u0026 tfP)\r\n\r\n%%\r\nfiletext = fileread('isLudicPrime.m');\r\nillegal = contains(filetext, 'oeis') || contains(filetext, 'read') || contains(filetext, 'persistent');\r\nassert(~illegal)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2024-11-23T15:57:21.000Z","deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-11-23T15:57:08.000Z","updated_at":"2025-07-30T17:52:45.000Z","published_at":"2024-11-23T15:57:21.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLudic numbers are formed by a sieve. Start with a list of the positive integers. Skip 1 and start with 2. Then delete every second number after 2 (i.e., 4, 6, 8, 10, etc.). Then move to the next number after 2—i.e., 3—and delete every third number (9, 15, 21, etc.). The next number is 5, so delete every fifth number (19, 37, etc.). Unlike the Sieve of Eratosthenes, this remaining numbers are not all prime. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to determine whether a number is a Ludic prime. The function should return three logical variables that answer these questions: Is it a Ludic prime? Is it a Ludic number? Is it prime? \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":61146,"title":"Extract numbers using a decaying sieve","description":"The Sieve of Eratosthenes is one method of determining primes. Starting with 2, one keeps 2 and removes 2x2, 3x2, 4x2, etc. Then the next remaining number is 3, and one keeps 3 and removes 2x3 (already removed), 3x3, 4x3 (already removed), etc. The sieving continues with multiples of 5, 7, 11, etc.\r\nThis problem involves a decaying sieve. In the Sieve of Eratosthenes, the gaps between the sieved numbers is constant at each step: if the next remaining number is 5 (say), then the gap is 5 as well, and the numbers removed are 10, 15, 20, 25, etc. In the decaying sieve, the gap decreases by 1 between numbers: if the next remaining number is 4, then the gaps are 3, 2, 1 so that the numbers removed are 7, 9, and 10. Notice that the decaying sieve removes a finite number of elements. \r\nThe sieve starts like this:\r\nThe first remaining number is 1. Keep 1. Because 1-1 = 0, no numbers are removed.\r\nThe next remaining number is 2. Keep 2 and remove 2+1 = 3.\r\nThe next remaining number is 4. Keep 4 and remove 4+3 = 7, 4+3+2 = 9, and 4+3+2+1 = 10.\r\nEt cetera \r\nWrite a function to apply the decaying sieve to numbers from 1 to the input number.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; min-height: 0px; white-space: normal; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: none; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 318.75px; display: block; min-width: 0px; padding-block-start: 0px; padding-inline-start: 2px; padding-left: 2px; padding-top: 0px; perspective-origin: 408px 159.375px; transform-origin: 408px 159.375px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe Sieve of Eratosthenes is one method of determining primes. Starting with 2, one keeps 2 and removes 2x2, 3x2, 4x2, etc. Then the next remaining number is 3, and one keeps 3 and removes 2x3 (already removed), 3x3, 4x3 (already removed), etc. The sieving continues with multiples of 5, 7, 11, etc.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 84px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 42px; text-align: left; transform-origin: 384px 42px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem involves a decaying sieve. In the Sieve of Eratosthenes, the gaps between the sieved numbers is constant at each step: if the next remaining number is 5 (say), then the gap is 5 as well, and the numbers removed are 10, 15, 20, 25, etc. In the decaying sieve, the gap decreases by 1 between numbers: if the next remaining number is 4, then the gaps are 3, 2, 1 so that the numbers removed are 7, 9, and 10. Notice that the decaying sieve removes a finite number of elements. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe sieve starts like this:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 81.75px; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 391px 40.875px; transform-origin: 391px 40.875px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe first remaining number is 1. Keep 1. Because 1-1 = 0, no numbers are removed.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe next remaining number is 2. Keep 2 and remove 2+1 = 3.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe next remaining number is 4. Keep 4 and remove 4+3 = 7, 4+3+2 = 9, and 4+3+2+1 = 10.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4375px; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2125px; text-align: left; transform-origin: 363px 10.2188px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEt cetera \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to apply the decaying sieve to numbers from 1 to the input number.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = decayingSieve(N)\r\n  y = 1:N;\r\nend","test_suite":"%%\r\nN = 20;\r\ny = decayingSieve(N);\r\ny_correct = [1 2 4 5 6 8 13 16 17 19];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nN = 100;\r\ny = decayingSieve(N);\r\ny_correct = [1 2 4 5 6 8 13 16 17 19 22 23 24 27 28 29 32 34 38 39 40 41 42 44 49 50 51 52 56 59 60 61 64 65 68 71 72 73 74 80 89 92 94 95 96];\r\nassert(isequal(y,y_correct))\r\n\r\n%%\r\nN = 1000;\r\ny = decayingSieve(N);\r\nlen_correct = 347;\r\nsum_correct = 167668;\r\nassert(isequal(length(y),len_correct))\r\nassert(isequal(sum(y),sum_correct))\r\n\r\n%%\r\nN = 15707;\r\ny = decayingSieve(N);\r\nlen_correct = 5000;\r\nsum_correct = 37983865;\r\nassert(isequal(length(y),len_correct))\r\nassert(isequal(sum(y),sum_correct))\r\n\r\n%%\r\nN = 200000;\r\ny = decayingSieve(N);\r\nlen_correct = 56635;\r\nsum_correct = 5563986488;\r\nlenp_correct = 14143;\r\nassert(isequal(length(y),len_correct))\r\nassert(isequal(sum(y),sum_correct))\r\nassert(isequal(length(y(isprime(y))),lenp_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2026-01-02T16:14:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":6,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2026-01-02T16:11:28.000Z","updated_at":"2026-02-26T10:21:53.000Z","published_at":"2026-01-02T16:11:28.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe Sieve of Eratosthenes is one method of determining primes. Starting with 2, one keeps 2 and removes 2x2, 3x2, 4x2, etc. Then the next remaining number is 3, and one keeps 3 and removes 2x3 (already removed), 3x3, 4x3 (already removed), etc. The sieving continues with multiples of 5, 7, 11, etc.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem involves a decaying sieve. In the Sieve of Eratosthenes, the gaps between the sieved numbers is constant at each step: if the next remaining number is 5 (say), then the gap is 5 as well, and the numbers removed are 10, 15, 20, 25, etc. In the decaying sieve, the gap decreases by 1 between numbers: if the next remaining number is 4, then the gaps are 3, 2, 1 so that the numbers removed are 7, 9, and 10. Notice that the decaying sieve removes a finite number of elements. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe sieve starts like this:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first remaining number is 1. Keep 1. Because 1-1 = 0, no numbers are removed.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe next remaining number is 2. Keep 2 and remove 2+1 = 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe next remaining number is 4. Keep 4 and remove 4+3 = 7, 4+3+2 = 9, and 4+3+2+1 = 10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEt cetera \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to apply the decaying sieve to numbers from 1 to the input number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60411,"title":"Compute a sequence with the whyphi sieve","description":"A few problems on Cody involve sieving. For example, Cody Problem 45367 involves the famous Sieve of Eratosthenes. CP 50811 uses the sieve of Flavius Josephus, and CP 50913 uses the golden sieve. \r\nThis problem uses a process that I will call the whyphi sieve: \r\nMake a list x of integers 1, 2, 3,… \r\nRemove the first term. That is, delete x(1).\r\nRenumber the terms. \r\nDelete x(2) and x(2+1)\r\nRenumber the terms. \r\nDelete x(3), x(3+2), and x(3+2+1). \r\nContinue renumbering and deleting terms in this way. \r\nWrite a function to compute the nth term of this sequence. ","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 266.033px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 133.017px; transform-origin: 407px 133.017px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 170.375px 7.79167px; transform-origin: 170.375px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA few problems on Cody involve sieving. For example, \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/45367\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eCody Problem 45367\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 138.075px 7.79167px; transform-origin: 138.075px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e involves the famous Sieve of Eratosthenes. \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/50811\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eCP 50811\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 127.967px 7.79167px; transform-origin: 127.967px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e uses the sieve of Flavius Josephus, and \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"https://www.mathworks.com/matlabcentral/cody/problems/50913\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"text-decoration-line: underline; \"\u003eCP 50913\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 73.5167px 7.79167px; transform-origin: 73.5167px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e uses the golden sieve. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 188.65px 7.79167px; transform-origin: 188.65px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis problem uses a process that I will call the whyphi sieve: \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003col style=\"block-size: 143.033px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: decimal; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 71.5167px; transform-origin: 391px 71.5167px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 105.775px 7.79167px; transform-origin: 105.775px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eMake a list x of integers 1, 2, 3,… \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 130.667px 7.79167px; transform-origin: 130.667px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRemove the first term. That is, delete x(1).\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 67.675px 7.79167px; transform-origin: 67.675px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRenumber the terms. \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 69.8333px 7.79167px; transform-origin: 69.8333px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDelete x(2) and x(2+1)\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 67.675px 7.79167px; transform-origin: 67.675px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eRenumber the terms. \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 107.567px 7.79167px; transform-origin: 107.567px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDelete x(3), x(3+2), and x(3+2+1). \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space-collapse: preserve; margin-left: 56px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 166.758px 7.79167px; transform-origin: 166.758px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eContinue renumbering and deleting terms in this way. \u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 181.108px 7.79167px; transform-origin: 181.108px 7.79167px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function to compute the nth term of this sequence. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = whyphiSieve(n)\r\n  c = 100*[0.000057513128234 0.093378634167431 -2.856145294974328]\r\n  y = polyval(c,n);\r\nend","test_suite":"%%\r\nassert(isequal(whyphiSieve(1),2))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(5),14))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(19),79))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(54),305))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(89),594))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(135),1032))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(336),3443))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(689),8948))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(1000),14685))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(4509),109040))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(whyphiSieve(428)),116991))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(whyphiSieve(620)),225368))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(10000),315192))\r\n\r\n%%\r\nassert(isequal(whyphiSieve(20000),793960))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":46909,"edited_at":"2024-06-04T15:38:44.000Z","deleted_by":null,"deleted_at":null,"solvers_count":4,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2024-05-28T02:46:53.000Z","updated_at":"2026-03-30T07:39:19.000Z","published_at":"2024-05-28T02:47:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eA few problems on Cody involve sieving. For example, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/45367\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCody Problem 45367\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e involves the famous Sieve of Eratosthenes. \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/50811\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCP 50811\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr/\u003e\u003cw:t\u003e uses the sieve of Flavius Josephus, and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/matlabcentral/cody/problems/50913\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eCP 50913\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e uses the golden sieve. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis problem uses a process that I will call the whyphi sieve: \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMake a list x of integers 1, 2, 3,… \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRemove the first term. That is, delete x(1).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRenumber the terms. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDelete x(2) and x(2+1)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRenumber the terms. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDelete x(3), x(3+2), and x(3+2+1). \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eContinue renumbering and deleting terms in this way. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to compute the nth term of this sequence. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"}],"term":"tag:\"sieve\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"sieve\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"sieve\"","","\"","sieve","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f20e4da0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f69f20e4d00\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f20e4440\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f20e5020\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f20e4f80\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f20e4ee0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f20e4e40\u003e":"tag:\"sieve\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f20e4e40\u003e":"tag:\"sieve\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"sieve\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"sieve\"","","\"","sieve","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f69f20e4da0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f69f20e4d00\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f69f20e4440\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f69f20e5020\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f69f20e4f80\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f69f20e4ee0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f69f20e4e40\u003e":"tag:\"sieve\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f69f20e4e40\u003e":"tag:\"sieve\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":50913,"difficulty_rating":"easy-medium"},{"id":50811,"difficulty_rating":"medium"},{"id":60990,"difficulty_rating":"medium"},{"id":60764,"difficulty_rating":"medium"},{"id":61146,"difficulty_rating":"medium"},{"id":60411,"difficulty_rating":"medium-hard"}]}}