0

Hello everyone there's is one question we have to give input a number than we have to check whether it's a square cube of any no

from math import log def prime(a): return all(False if a%i==0 else True for i in range(2,(a//2)+1)) def equivalent_power(a): if prime(a): return 'NO' else: for i in range(2,(a//2)): n=log(a,i) if i**int(n)==a: return 'YES' else: continue return 'NO' if __name__=='__main__': print(equivalent_power(int(input()))) If I'm giving input 1000 why it giving me Answer No

15th Apr 2022, 9:23 AM
Akash Gupta
Akash Gupta - avatar
9 Respuestas
0
squire Or cube? what is your idea of n= log(a, I)?
15th Apr 2022, 10:19 AM
Jayakrishna 🇮🇳
0
# cube: n = int(input('~>')) m = n**(1/3) if m==int(m): print('Yes') else: print('No') # your way may take a longer time as involves calls of functions, but I wonder about generators ...
15th Apr 2022, 3:10 PM
Ervis Meta
Ervis Meta - avatar
0
Ervis Meta - SoloHelper why it giving no on thousand?
16th Apr 2022, 1:00 PM
Akash Gupta
Akash Gupta - avatar
0
Jayakrishna🇮🇳 bro actually it taking log value i gave you one example suppose you give input 1000 okay now log (1000,2) it means log base 2( 1000) is 9.6 than it will check if it's is equal to input or not like- 2**9.6==1000 and keep incremented when the value of log. How can i send photo here you can understand with photo it's hard to explain in text.
16th Apr 2022, 1:37 PM
Akash Gupta
Akash Gupta - avatar
0
Akash Gupta that is because of the way Python interpret floats, for 1000 it will give 9.99...8 and ~9.9!=10 so it won't print 'Yes'.
16th Apr 2022, 1:44 PM
Ervis Meta
Ervis Meta - avatar
0
Ervis Meta - SoloHelper please check your code once having another error also it will giving no on 64,216 ?? And i can't understand your logic behind giving float value on 1000 ?
16th Apr 2022, 7:35 PM
Akash Gupta
Akash Gupta - avatar
0
Akash Gupta then instead of n= log(a, I), use its ceil value like n=ceil(log(a,i))
16th Apr 2022, 7:46 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 bro can you do that it giving error while doing this
17th Apr 2022, 3:51 AM
Akash Gupta
Akash Gupta - avatar
0
Akash Gupta from math import log, ceil def prime(a): return all(False if a%i==0 else True for i in range(2,(a//2)+1)) def equivalent_power(a): if prime(a): return 'NO' else: for i in range(2,(a//2)): n=ceil(log(a,i)) #take roundup value if i**int(n)==a: return 'YES' else: continue return 'NO' if __name__=='__main__': print(equivalent_power(int(input())))
17th Apr 2022, 10:43 AM
Jayakrishna 🇮🇳