11

Here's a task for the bored of you ;)

"Write a python script that prints out all numbers y from one to 10**30(including 10**30) that have two of these traits: [n**5=y, m**3=y, x**2=y] but not the other one; n and m are whole numbers."

Correct answer was about 103000
I can't seem to find the solution... Here's my (failed) try:

Comments
  • 2
    Wth is 10**30
  • 0
    @RazorSh4rk squared
  • 3
    Yeah, you should at most have one loop.
  • 1
    A semi efficient "if" statement would be to reverse the traits into square roots like n=sqrt(y,3), followed by a check to see if n is a whole number.

    There is likely a quick way to do this as I'm not a python expect, but one way would be to check if n == int(n)
    Or if n==floor(n).

    int(),floor(), and sqrt() could have different names, and may be part of a package so the call may be math.floor() or something.
  • 1
    @brettmoan use int(n)
    Built in, and does the same as math.floor on python
  • 1
    @brettmoan Additionally, you don't make any statement about "x" does "x" also need to be a whole number?

    If not, that condition is always true, as there is some number y(not necessarily a whole number), that is the square of every number between 1 and 10^30.

    Otherwise the checks are for a square root (root 2), cube root (root 3) and a root 5 (whatever that's called, pentahedron root?)
    Where 2 are whole numbers and the other isn't.
    First use a for loop over a while for conciseness.
    I.e."for(y=1;y<=10**30;y++)"
    Second do check for m like this:
    m=math.sqrt(y,3)
    if m==int(m):
    mbool=True
    else
    mbool=False
    // total keeps track of the 3 conditions
    if mbool:
    total++

    // do similar check for n
    ...
    // do similar check for x
    ...

    if total == 2:
    print y
  • 0
    @darksideplease oh, thanks, not really familiar with python syntax, ill try to do this in some other language
  • 1
    @brettmoan however, python cannot get exact Sqrt for very large number, so the problem is not as easy as expected. Some possible solutions are given here http://stackoverflow.com/questions/... and then have to also apply it similarly for **3 and **5 cases for solving this question
  • 2
    Taking a screenshot with a phone. Nice
  • 0
    @UnknownDev I didn't want to sign in on my laptop
Add Comment