tag:blogger.com,1999:blog-7958828565254404797.post2631365890669947992..comments2020-07-09T14:02:26.084-07:00Comments on ListenData: Check if a number is prime with ExcelDeepanshu Bhallahttp://www.blogger.com/profile/09802839558125192674noreply@blogger.comBlogger25125tag:blogger.com,1999:blog-7958828565254404797.post-33675595883412736242020-06-22T01:26:44.706-07:002020-06-22T01:26:44.706-07:00Why test for the square root again? It's alrea...Why test for the square root again? It's already included in the virtual array. <br />When evaluated as an array formula, the offset function creates an array from 2 to the square root (rounded up, so the square root is always included). Your function just adds a test for the un-rounded square root. But, the only time an un-rounded square root would make a difference (ie, be a divisor) is if it happens to be an integer, which is already included in the array as the round functions don't change an integer. <br />As long as you make it an array formula with Ctrl+Shift+Enter, this modification won't change anything.Andrewhttps://www.blogger.com/profile/07597869303241688241noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-9155535225118175302020-06-21T23:55:47.209-07:002020-06-21T23:55:47.209-07:00The correct formula should be like this:
=IF($C$4...The correct formula should be like this: <br />=IF($C$4=2,"Prime",IF(AND(MOD(C4,ROW(OFFSET($A$2,,,ROUNDUP(SQRT($C$4),0)-1)))<>0,MOD($C$4,SQRT($C$4))<>0),"Prime","Not Prime"))euelvishttps://www.blogger.com/profile/06620940822548663532noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-69430119804179833862020-05-24T16:02:56.838-07:002020-05-24T16:02:56.838-07:00it says not prime for 1681 in my case
it says not prime for 1681 in my case<br />Sulamanhttps://www.blogger.com/profile/05039172303879319841noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-5505461593511263102020-04-27T16:53:40.307-07:002020-04-27T16:53:40.307-07:00The formula creates a virtual array from 2 (which ...The formula creates a virtual array from 2 (which is why A2 is used in the formula) to the square root of the number (because there are no possible multiples larger than the square root of a given number). That is the "OFFSET($A$2,,,ROUNDUP(SQRT(B4),0)-1)" section.<br /><br />Next, every function the array is passed to acts on every entry in that array until it is summarized by the AND function.<br />So first the array is passed to the ROW function which places the "row number" in each array entry. The array of numbers is then passed to the MOD function as the divisor. The formula then returns the remainder when the number in question is divided by the number in that entry in the array. That is the "MOD(B4,...)" section. It then tests each entry to see if that result is equal to 0, if an entry in the array is 0, then it returns FALSE. The array is now a list of TRUE and FALSE values that are then summarized with the AND function. AND takes the array of Boolean values and returns a single Boolean value.<br />So, if the number is not prime then there is a divisor somewhere in the array of integers and the MOD function returns 0, the logical comparator "<>0" then returns FALSE which then makes AND false, causing the IF function to return "Not Prime".<br /><br />Because the formula uses an array, you MUST tell Excel to process it as an Array Formula by entering it with Ctrl+Shift+Enter. Otherwise, if you don't make it an array formula it will return false positives (like 9, 81, 1681, and now the latest entry, 21). Andrewhttps://www.blogger.com/profile/07597869303241688241noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-79587300415603699092020-04-27T16:53:20.463-07:002020-04-27T16:53:20.463-07:00This comment has been removed by the author.Andrewhttps://www.blogger.com/profile/07597869303241688241noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-89846300042312004952020-04-27T10:50:47.349-07:002020-04-27T10:50:47.349-07:00This Formula is not correct because for 21 it also...This Formula is not correct because for 21 it also says it is a prime number but 21 can be divided by 3 and so this formula is not perfect i want a perfect formula brotherAnonymoushttps://www.blogger.com/profile/17085462098926489432noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-48440749125735146532020-04-16T17:29:58.344-07:002020-04-16T17:29:58.344-07:00Thanks, this formula works completely fine with me...Thanks, this formula works completely fine with me. I would really appreciate, if you could give a little bit explanation for this particular part - IF(AND(MOD(B4,ROW(OFFSET($A$2,,,ROUNDUP(SQRT(B4),0)-1)))<>0),"Prime","Not Prime"))Shreyahttps://www.blogger.com/profile/02363939777240926658noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-13906146032677989612019-11-18T07:50:59.036-08:002019-11-18T07:50:59.036-08:00The formula works, the most common mistake is not ...The formula works, the most common mistake is not making it an array formula by pressing Ctrl+Shift+Enter. If you don't make it an array formula it will return false positives (like 9, 81, and 1681). Andrewhttps://www.blogger.com/profile/07597869303241688241noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-87814995093876350442019-11-13T05:46:06.385-08:002019-11-13T05:46:06.385-08:00try 1681 it says its prim but 41^2 = 1681
try 1681 it says its prim but 41^2 = 1681<br />chris farmerhttps://www.blogger.com/profile/12914158173497352710noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-8442830819627372002019-10-16T08:23:25.986-07:002019-10-16T08:23:25.986-07:0074 Prime
75 Not Prime
76 Not Prime
77 Not Prime
78...74 Prime<br />75 Not Prime<br />76 Not Prime<br />77 Not Prime<br />78 Not Prime<br />79 Prime<br />80 Not Prime<br />81 Not Prime<br />82 Prime<br />83 Prime<br />84 Not Prime<br />85 Not Prime<br />86 Prime<br />87 Not Prime<br />88 Not Prime<br />89 Prime<br />90 Not Prime<br />91 Not Prime<br />92 Not Prime<br />93 Not Prime<br />94 Prime<br />UNKNOWNhttps://www.blogger.com/profile/12437561717128712767noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-31375139556513624502019-07-17T06:36:50.755-07:002019-07-17T06:36:50.755-07:00Thank you that is genius, works fine for me, shows...Thank you that is genius, works fine for me, shows 6 and 9 as prime. Mark Wadsworthhttps://www.blogger.com/profile/07733511175178098449noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-23916881039158428032019-03-23T11:38:28.780-07:002019-03-23T11:38:28.780-07:00Shows 6 as a prime, not correctShows 6 as a prime, not correctAnonymoushttps://www.blogger.com/profile/06150507672197265790noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-31012828008197920442019-01-05T07:58:18.743-08:002019-01-05T07:58:18.743-08:00It works fine for me. Make sure to press CTRL + SH...It works fine for me. Make sure to press CTRL + SHIFT + ENTER after entering the formula but BEFORE clicking away. You will know that you entered it correctly if selecting the cell shows<br />{=IF(B4=2,"Prime",IF(AND(MOD(B4,ROW(OFFSET($A$2,,,ROUNDUP(SQRT(B4),0)-1)))<>0),"Prime","Not Prime"))}<br />note the {} brackets.<br />Also note that entering the brackets manually does NOT work; you have to press CTRL + SHIFT + ENTER to get the brackets.Michaelhttps://www.blogger.com/profile/16769280621950269831noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-26123825515511066772018-07-23T19:21:04.500-07:002018-07-23T19:21:04.500-07:00Careful using this with numbers 81 and larger... Careful using this with numbers 81 and larger... Anonymoushttps://www.blogger.com/profile/07902923162209164375noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-31421292256629267652017-09-12T00:54:32.071-07:002017-09-12T00:54:32.071-07:00Clever!! I never would have thought of using an ar...Clever!! I never would have thought of using an array formula iterating along a virtual array to create a "for loop" inside an excel formula! I'm definitely going to have to remember that technique in the future!<br />Though, as evidenced by the comments, that technique is extremely advanced (and thus confusing) for most people. Perhaps a link to a post with an explanation of the technique would help.Andrewhttps://www.blogger.com/profile/07597869303241688241noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-1472010642886061182017-05-22T19:58:14.272-07:002017-05-22T19:58:14.272-07:00This comment has been removed by the author.TheLaziestWizardhttps://www.blogger.com/profile/18196662408777209396noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-56296987025668539372017-05-22T19:56:05.106-07:002017-05-22T19:56:05.106-07:00This comment has been removed by the author.TheLaziestWizardhttps://www.blogger.com/profile/18196662408777209396noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-1472524065009220622017-05-22T19:46:49.778-07:002017-05-22T19:46:49.778-07:00This comment has been removed by the author.TheLaziestWizardhttps://www.blogger.com/profile/18196662408777209396noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-90076157646434041582017-05-22T19:44:47.434-07:002017-05-22T19:44:47.434-07:00This comment has been removed by the author.TheLaziestWizardhttps://www.blogger.com/profile/18196662408777209396noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-35027662014045156492017-03-16T11:00:47.384-07:002017-03-16T11:00:47.384-07:00It says 'Not Prime' for 111,111,111. You c...It says 'Not Prime' for 111,111,111. You can save your workbook to any cloud drive and share link with me to debug.Deepanshu Bhallahttps://www.blogger.com/profile/09802839558125192674noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-22474975348467970072017-03-15T14:25:33.362-07:002017-03-15T14:25:33.362-07:00Doesn't seem to be 100% accurate, for example,...Doesn't seem to be 100% accurate, for example, For the input I entered 111,111,111. It said it was prime, although it can be divided by 9 and 3 at least. Any idea what may cause this kind of behavior? I don't really understand how the function works, so I can't diagnose the problem myself.portalsrule123noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-66521693155094055792016-09-14T15:22:59.465-07:002016-09-14T15:22:59.465-07:00Anonymous, it is very easily copied into any workb...Anonymous, it is very easily copied into any workbook, and it works exactly as advertised. The A2 reference makes no difference - a little investigation would have shown you that. And on that note, even if the formula wasn't directly translatable, would it really hurt to have to -gasp!- do a little of your own homework? There's a lot to learn from this post - that would be "the point" of publishing it.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-72442545832181533402016-03-15T07:48:22.120-07:002016-03-15T07:48:22.120-07:00Your formula references A2, but doesn't say wh...Your formula references A2, but doesn't say what I should be putting there. It's great that your formula works for your specific workbook, but if it can't be easily copied into another, then what is the point of publishing it. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-36891155280772715282016-01-17T13:48:56.365-08:002016-01-17T13:48:56.365-08:00It is working fine for 9. Download the workbook (l...It is working fine for 9. Download the workbook (link provided in the article)Deepanshu Bhallahttps://www.blogger.com/profile/09802839558125192674noreply@blogger.comtag:blogger.com,1999:blog-7958828565254404797.post-91804775918985581502016-01-04T22:47:06.159-08:002016-01-04T22:47:06.159-08:00Not working for 9. Problem with some indirect addr...Not working for 9. Problem with some indirect addressing.Varunhttps://www.blogger.com/profile/18440793638500162780noreply@blogger.com