.. module:: curiosos Nombres curiosos ================ Implementa les funcions següents al mòdul :mod:`curiosos` (fitxer :file:`curiosos.py`): .. function:: es_suma_consecutius(n, a) Donats dos enters positius :math:`n` i :math:`a`, tals que :math:`a < n`, retorna :code:`True` si :math:`n` és igual a alguna suma de nombres consecutius a partir de :math:`a`: :math:`n = a + (a+1) + (a+2) + \cdots + (a+p)`, o :code:`False` altrament. Per exemple, si :math:`n = 9` i :math:`a = 4`, la funció ha de retornar :code:`True` ja que :math:`4+5` és igual a :math:`9`. En canvi, per :math:`n=9` i :math:`a=3`, la funció ha de retornar :code:`False` ja que :math:`3` i :math:`3+4` són inferiors a :math:`9` però :math:`3+4+5` és superior a :math:`9`. Per :math:`n= 6` i :math:`a=1`, la funció ha de retornar :code:`True` ja que :math:`1+2+3 = 6`. .. literalinclude:: test-es_suma_consecutius.txt :language: python3 :start-after: ---- inici :end-before: ---- fi Trobaràs més tests al fitxer :download:`test-es_suma_consecutius.txt`. .. function:: es_curios(n) Donat l'enter positiu :math:`n`, retorna :code:`True` si :math:`n` és *curiós*, o :code:`False` altrament. Cal que la funció :func:`es_curios` cridi :func:`es_suma_consecutius`. Un nombre enter és *curiós* si és igual a alguna suma d'enters positius consecutius inferiors a ell mateix. Per exemple, :math:`6` i :math:`9` són curiosos, però :math:`8` no ho és. .. literalinclude:: test-es_curios.txt :language: python3 :start-after: ---- inici :end-before: ---- fi Trobaràs més tests al fitxer :download:`test-es_curios.txt`. Modifica les dues funcions anteriors de la forma següent: .. function:: quina_suma_consecutius(n, a) Donats dos enters positius :math:`n` i :math:`a`, tals que :math:`a < n`, retorna :math:`p` si existeix un nombre :math:`p` tal que :math:`n = a + (a+1) + (a+2) + \cdots + (a+p)`, o :math:`0` altrament. Per exemple: .. literalinclude:: test-quina_suma_consecutius.txt :language: python3 :start-after: ---- inici :end-before: ---- fi Trobaràs més tests al fitxer :download:`test-quina_suma_consecutius.txt`. .. function:: quin_curios(n) Donat l'enter positiu :math:`n`, retorna :math:`a` i :math:`p` si existeixen els nombres :math:`a` i :math:`p` tals que :math:`a < n` i :math:`n = a + (a+1) + (a+2) + \cdots + (a+p)`, o :math:`0` i :math:`0` altrament. Cal que la funció :func:`quin_curios` cridi :func:`quina_suma_consecutius`. Per exemple: .. literalinclude:: test-quin_curios.txt :language: python3 :start-after: ---- inici :end-before: ---- fi Trobaràs més tests al fitxer :download:`test-quin_curios.txt`. .. rubric:: Solució Disposes de solucions al fitxer :download:`curiosos.py`