Advertisement
cardel

Grupo P10 Ejemplo 1

May 11th, 2021
1,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. '''
  2. Autor: Carlos A Delgado
  3. Fecha: 11 de Mayo de 2021
  4. Algoritmo pereira_es_potencia
  5. Variables
  6.     x,y,b: int
  7. Inicio
  8.     obtener x,y #Parametros
  9.     Si y == 0 O y == 1 O y < 0
  10.         retorna Falso
  11.     Sino   
  12.         b = int(log2(y)/log2(x))
  13.         Si x**b == y
  14.             Retorno True
  15.         Sino
  16.             Retorna Falso
  17.         Fin_SI
  18.     Fin_SI 
  19. '''
  20. import math as mt
  21. def pereira_es_potencia(x:int,y:int):
  22.     if y == 0 or y == 1 or y < 0:  #if y <= 1
  23.         return False
  24.     else:
  25.         b = int(mt.log2(y)/mt.log2(x)) # mt.log2(y)//mt.log2(x)
  26.         if x**b == y:
  27.             return True
  28.         else:
  29.             return False
  30.  
  31.  
  32. print(pereira_es_potencia(2,8)) #True
  33. print(pereira_es_potencia(3,27)) #True
  34. print(pereira_es_potencia(3,35)) #False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement