Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python.Happy Primes a) A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural

Python.Happy Primes a) A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Write a function that returns true if an int is prime. If the int is not prime or if it is an invalid input return false. Write your code efficiently. b) Happy has many definitions (even in mathematics). For our purposes, a happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers (or sad numbers). For example, 19 is happy, as the associated sequence is: 12 + 92 = 82 82 + 22 = 68 62 + 82 = 100 12 + 02 + 02 = 1 Write a python function that returns true if an int is happy. c) Write a python unction that returns true if an int is a happy prime, the int is both happy and a prime. d) Write a python function that computes and prints the first 100 happy primes in a comma separated list. 7, 13, 19, e) Write a function that computes and prints the first 100 sad primes in a comma separated list. 2, 3, 5, 11, Note: Please consider the efficiency of your code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Solve for a, b, c, d if 5 2 3 3

Answered: 1 week ago