Участник:Fomberg/finstp — различия между версиями

Материал из DISCOPAL
Перейти к: навигация, поиск
(Новая страница: «https://www.codechef.com/problems/FINSTP #task https://www.codechef.com/viewsolution/43853901 #submition/solution <code-python> def prime_factors_chec…»)
 
 
Строка 1: Строка 1:
https://www.codechef.com/problems/FINSTP      #task
+
https://www.codechef.com/problems/FINSTP      #task <br>
 
https://www.codechef.com/viewsolution/43853901    #submition/solution
 
https://www.codechef.com/viewsolution/43853901    #submition/solution
  

Текущая версия на 12:56, 15 марта 2021

https://www.codechef.com/problems/FINSTP #task
https://www.codechef.com/viewsolution/43853901 #submition/solution

 
def prime_factors_check(n):
    dictionary = dict()
    if n == 1:
        return 0
 
    dictionary['2'] = 0
    dictionary['3'] = 0
    while n%2 == 0:
        n = n/2
        dictionary['2'] += 1
    while n%3 == 0:
        n = n/3
        dictionary['3'] += 1
    if n != 1:
        return -1
    elif dictionary['3'] == dictionary['2']:
        return dictionary['3']
    elif dictionary['3'] > dictionary['2']:
        return (dictionary['3'] - dictionary['2']) + dictionary['3']
    elif dictionary['2'] > dictionary['3']:
        return -1
    else:
        print("that's literally imposible.")
 
n = (int(input()))
 
answers = []
for i in range(n):
    number = int(input())
    answers.append(prime_factors_check(number))
 
for answer in answers:
    print(answer)