Quiz - 3ΒΆ
We say that a natural number is triangular if it is the product of three consecutive natural numbers.
Example: 120 is triangular, since 4 x 5 x 6 = 120. Given a non-negative integer n
, check if n
is triangular.
Return True
if the number is triangular or False
if it is not.
Indicate how to make change using the minimum number of bills.
Your algorithm should read the amount of the bill to be paid, cobro
, and the amount
paid, pago
, without taking into account the cents.
Suppose the bills for change are 50, 20, 10, 5, 2 and 1, and that none of them is missing in the cash register.
Return a list with the quantity of each bill that represents the change.
The first element of the list matches the quantity of 50,
the next with 20, and so on until 1. (The same order as shown above).
Examples:
calculate_change(50, 100)
-> [1,0,0,0,0,0]
calculate_change(92, 100)
-> [0,0,0,1,1,1]
Check whether a positive integer n
is prime.
Return True
if it is prime or False
if it is not.
Given a positive integer n
, determine its prime factorization
also calculating the multiplicity of each factor.
Return a dictionary with the keys as primes and their respective values as the
frequency of the prime in the prime factorization of the number.
Examples:
factors(5)
-> {5:1}
factors(420)
-> {2:2, 3:1, 5:1, 7:1}
Make a program that asks for a positive integer n
and shows it inverted.
For example: 1234 generates 4321. Return the inverted number.
Examples:
invert_number(123456789)
-> 987654321
invert_number(1000)
-> 1