+ Reply to Thread
Results 1 to 7 of 7

Help prime co prime

  1. #1
    Registered User
    Join Date
    11-20-2016
    Location
    TRINIDAD
    MS-Off Ver
    2013
    Posts
    3

    Help prime co prime

    help im trying to output prime and coprime AND NEITHER DEPENDING ON THE NUMBERand its not working
    i have been trying for hours and its not working
    swift help would be appreciated

    Please Login or Register  to view this content.
    Last edited by alansidman; 11-20-2016 at 07:35 PM. Reason: code tags

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

    Re: Help prime co prime

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    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

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Help prime co prime

    One way:

    A
    B
    C
    1
    264,627,858,537,807
    3
    B1: =isprime(A1, TRUE)
    2
    250,522,486,845,971
    6719759
    3
    336,502,419,415,881
    3
    4
    213,751,729,707,615
    5
    5
    215,771,119,714,057
    164513
    6
    384,515,184,772,903
    17
    7
    383,451,182,203,411
    7
    8
    234,532,507,205,987
    TRUE
    9
    328,100,503,187,517
    3
    10
    200,768,597,700,379
    17


    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    11-20-2016
    Location
    TRINIDAD
    MS-Off Ver
    2013
    Posts
    3

    Re: Help prime co prime

    interesting but can u tell me whats wrong with my code?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Help prime co prime

    I don't know how it's supposed to work. "co-prime" is a property of two numbers, not 1.

  6. #6
    Registered User
    Join Date
    11-20-2016
    Location
    TRINIDAD
    MS-Off Ver
    2013
    Posts
    3

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

    Re: Help prime co prime

    "Doesn't work" can be a rather unhelpful way to describe a problem. Can you explain what you mean by "doesn't work"? When I copy your function into a blank worksheet and use it, it seems to "work" (meaning that it runs without syntax or run-time errors) just fine. It returns 0 (the value written to Excel for empy variants) for non-prime numbers and "prime" for prime numbers -- as it has been instructed to do. I would guess that these are not your expected results. What are your expected results?

    As a debugging step, I added a few Stop statements to your UDF.
    Please Login or Register  to view this content.
    I recommend that you setup your spreadsheet and see what is happening inside of the code. Identify where the code is doing something you don't expect. Then you will be in a better position to change the code to do what you want. If you need help making the edits, tell us where it is doing something unexpected or unwanted, explain what you want it to do instead, and we should be able to help you edit the code.

    I also note, like shg, that there is nothing in the code for computing coprimes. The code as written will only identify prime or not-prime numbers. I note, from the Wikipedia page for coprimes (https://en.wikipedia.org/wiki/Coprime ) that there may be simpler algorithms based on some of the properties of coprime numbers.
    One algorithm might use the built in GCD() function https://support.office.com/en-us/art...c-ddfc21b5073a
    Another might use the built in LCM() function. https://support.office.com/en-us/art...c-06ede5563c94
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. Prime numbers macro
    By kaue in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-17-2020, 09:08 AM
  2. Hello from G-Prime
    By G-Prime in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 07-27-2015, 08:50 AM
  3. prime number
    By abbccc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2013, 08:09 AM
  4. prime-factors
    By abbccc in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 04-04-2013, 06:11 AM
  5. Prime numbers
    By Gearcutter in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-08-2007, 09:03 AM
  6. [SOLVED] Prime Number just for fun
    By Paul Breslin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-13-2006, 05:21 PM
  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