Jump to content
BrainDen.com - Brain Teasers
  • 0


Guest K Sengupta
 Share

Question

Determine the probability that for a base ten positive integer x chosen at random from 1 to 9999 inclusively, this relationship is satisfied:

(sod(x))2 = x+2, where sod(n) denotes the sum of the digits in the base ten representation of n.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0


public static void sumofdigitslinear(int cap)

    {

        System.out.println("~~~CAP "+cap);

        int numSatisfy = 0;

        for (int i=1; i<=cap; i++)

        {

            if (sodsquared(i) == i+2)

            {

                numSatisfy++;

                System.out.println(i);

            }

        }

        System.out.println("~~~~~\n\n\t"+numSatisfy+" out of "+cap);

        System.out.println("\t"+((double)numSatisfy/(double)cap));

    }

    public static int sodsquared(int x)

    {

        int con = 0;

        while (x > 0)

        {

            con += (x % 10);

            x /= 10;

        }   

        return con*con;

    }



~~~CAP 9999

2

23

62

119

194

287

398

~~~~~


	7 out of 9999

	7.000700070007E-4

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...