+ Reply to Thread
Results 1 to 13 of 13

Prime and Composite numbers

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-17-2020
    Location
    Uzbek
    MS-Off Ver
    Office 365, V 2212
    Posts
    201

    Post Prime and Composite numbers

    Dear Excel Experts,

    I have numbers in A2, B2, C2, D2, E2, F2 and would like to count how many Prime and Composite numbers are there. For instance 2, 3, 4, 5, 6, 7 = 4/2

    And also would like to know all numbers put together is Prime or Composite. For Instance, 2, 3, 4, 5, 6, 7 =Composite (because all numbers put together is 234567)

    Appreciate if somebody could provide me a formula for both the above scenarios.

    Thanks in advance
    Attached Files Attached Files
    Last edited by Gulya; 12-25-2020 at 02:29 PM. Reason: forgot to attach

  2. #2
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365
    Posts
    3,187

    Re: Prime and Composite numbers

    Hi,
    Fast answers need clear examples. Post a small Excel sheet (not a picture) showing realistic & representative sample data WITHOUT confidential information (10-20 rows, not thousands...) and some manually calculated results. Just before posting, scroll down to GO ADVANCED, click, and then scroll down to MANAGE ATTACHMENTS and click again. Now follow the instructions at the top of that screen.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: Prime and Composite numbers

    LOOK here---> https://www.listendata.com/2013/05/c...n%20is%20prime.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Prime and Composite numbers

    Quote Originally Posted by Gulya View Post
    For Instance, 2, 3, 4, 5, 6, 7 =Composite (because all numbers put together is 234567)
    Not because "all numbers put together" are 234567, but because 234567 is not prime. Its factors are 3, 3, 67, 389.

    Of 2,3,4,5,6,7, only 4 and 6 are composite numbers. 2, 3, 5 and 7 are prime numbers.

    Are you really looking for the prime and composite numbers that can be made by combining the (single) digits in A2:F2?

    In other words, construct all 1, 2, 3, 4, 5 and 6-digit numbers using the digits in A2:F2, and classify them as prime or not (= composite)?

  5. #5
    Forum Contributor
    Join Date
    07-17-2020
    Location
    Uzbek
    MS-Off Ver
    Office 365, V 2212
    Posts
    201

    Re: Prime and Composite numbers

    Quote Originally Posted by joeu2004 View Post

    Are you really looking for the prime and composite numbers that can be made by combining the (single) digits in A2:F2?

    In other words, construct all 1, 2, 3, 4, 5 and 6-digit numbers using the digits in A2:F2, and classify them as prime or not (= composite)?
    Yes, after using the digits in A2:F2 and classify them as prime or composite

  6. #6
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Prime and Composite numbers

    Quote Originally Posted by joeu2004 View Post
    In other words, construct all 1, 2, 3, 4, 5 and 6-digit numbers using the digits in A2:F2, and classify them as prime or not (= composite)?
    Quote Originally Posted by Gulya View Post
    Yes, after using the digits in A2:F2 and classify them as prime or composite
    Okay, that helps to clarify. But the example Excel file attached to the OP does little-to-nothing to clarify further. It contains the following.

    A B C D E F G H
    1 A B C D E F Prime/Composite Prime/Composite
    2 2 3 4 5 6 7 4/2 Composite


    The "value" in G2 is not a number; instead, it is in the form of a fraction. It is neither prime nor composite. At best, we might interpret your intent to mean "4 divided by 2". But that is 2, which is a prime, not a composite as indicated in H2.

    -----

    Please provide a table, in one form or another, that demonstrates several concrete examples of how you want to combine several digits from A2:F2 into a number, which would be classified as prime or composite.

    Of course, you would fill in the table manually, for now, since you are asking for an Excel (or VBA?) implementation to accomplish it.

    For example, would your table look like following?

    A B C D E F G H
    1 digits.... number prime/composite?
    2 2 3 4 5 6 7 64723 composite
    3 23 prime
    4 354627 composite
    5 43257 composite
    6 457 prime


    You already agreed that the number would be 1 to 6 digits.

    Is each randomly-selected cell in A2:F2 used only once in the 1-to-6-digit number in column G? For example, if the digits in A2:F2 are unique, would 23423 be allowed (uses A2 and B2 twice each, by coincidence)?

    (But if 2 appears in two cells and 3 appears in two cells, 23423 should be allowed.)

    Have tried the formula that alansidman points to in response #3 in column H?

    If you need help with that, ask alansidman.
    Last edited by joeu2004; 12-25-2020 at 07:25 PM.

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: Prime and Composite numbers

    Look at post #3. If prime then not composite. Formula shown will provide solution to that issue.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,453

    Re: Prime and Composite numbers

    In the OP you asked for a formula (singular), but I don't know that this gets solved in one single formula.

    In other words, construct all 1, 2, 3, 4, 5 and 6-digit numbers using the digits in A2:F2, and classify them as prime or not (= composite)?
    Do you have an algorithm in mind? Here's what I see needing to happen (mostly outline -- no real programming, yet).

    1) A permutation algorithm to combine the 6 digits into 1 to 6 digit numbers. I think most people prefer VBA or similar programming language for generating permutations because it can be done with a series of nested For...Next loops. I have a short tutorial here (https://www.excelforum.com/tips-and-...thout-vba.html ) for generating permutations that talks about both VBA nested loops and worksheet formula only approaches. Have a look and see if that helps with the "generate all the permutations" part of the problem.
    2) Check if each number is prime or composite. The big question here is what kind of algorithm do you want to use. Do you want something long and laborious like trial division? Do you want to use a sieve (like the sieve of eratosthenes https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes ) to check for primes? Often times, I think the easiest would be to find a list of prime numbers on the internet (here's a list in .csv format, if we trust the source to be accurate http://www.mathematical.com/primes0to1000k.html ), store that in the spreadsheet, and then run a simple lookup on that list to see if a number exists in that list.
    3) You are asking for a text string "#composite/#prime" kind of output. After generating the permutations and determining which are prime and composite, we just need to count the number of each and concatenate together into the text string. As an Excel formula, this might look like =CONCATENATE(COUNTIFS(list,"composite"),"/",COUNTIFS(list,"prime")). I am assuming that steps 1 and 2 would generate a column/list of "composite" or "prime" values that COUNTIFS() can count.

    Any thoughts on how you would like to proceed?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Prime and Composite numbers

    An alternative formula to achieve the same end result:

    =IF(A3=2,"Prime",IF(AND(MOD(A3,ROW(INDIRECT("2:"&ROUNDUP(SQRT(A3),0))))<>0),"Prime","Composite"))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  10. #10
    Forum Contributor
    Join Date
    07-17-2020
    Location
    Uzbek
    MS-Off Ver
    Office 365, V 2212
    Posts
    201

    Post Re: Prime and Composite numbers

    Could you please check the attached sample, the formula is giving wrong result.. Thanks
    Attached Files Attached Files

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Prime and Composite numbers

    You seem to be using an older version of Excel than me. So, please refer to the attached file. If the formulae are enclosed within a pair of { }, these are array formulae.

    These are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see the curly brackets { } appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    07-17-2020
    Location
    Uzbek
    MS-Off Ver
    Office 365, V 2212
    Posts
    201

    Re: Prime and Composite numbers

    working perfectly, thanks a lot Glenn Kennedy
    Last edited by AliGW; 12-26-2020 at 09:02 AM. Reason: PLEASE don't quote unnecessarily!

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Prime and Composite numbers

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It would also be very nice if you were to just click the Add Reputation button at the foot of any of the posts of members who helped you reach a solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Count Prime and Composite numbers
    By Gulya in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 08-28-2020, 04:53 PM
  2. Prime numbers macro
    By kaue in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-17-2020, 09:08 AM
  3. detect the 6 prime numbers in the list
    By jorel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2020, 02:33 PM
  4. [SOLVED] Prime and Composite Numbers
    By Billiebones in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 11-24-2019, 04:52 AM
  5. using excel VBA find and higlight in red all prime numbers in a table of numbers
    By TeraFumba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2017, 07:30 AM
  6. Prime numbers
    By Gearcutter in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-08-2007, 09:03 AM
  7. [SOLVED] Prime Numbers
    By Flyone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2005, 10:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1