Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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. -
@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 -
@darksideplease oh, thanks, not really familiar with python syntax, ill try to do this in some other language
-
@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
Related Rants
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:
undefined
python
maths
fuckthisshit