DEV Community

Cover image for Prime Number Problems Explained - Easy Logic with Python Code
Ebenezer
Ebenezer

Posted on

Prime Number Problems Explained - Easy Logic with Python Code

Hey guys

Good day...

This Blog contains the tasks which is given or Assigned by trainer.

SO first problem is
1) The number of prime numbers between 11 and 60 is________.
My Logic:
Intialize the two pointer 11 and 60 and run the while loop upto 60. Find the prime and print it .
Code:

Output:

Second task is
2) Find the 4 Digit Prime Number - Smallest

My Logic:
Run the loop between 1000 to 9999 so we all know first prime number is the smallest that's why I breaked the loop
Code:


Output:

Third task is
3) Write the smallest and the biggest two digit prime number. [First, Last --> Greatest Common Divisor]

My Logic:
Initialize the first and last variable with 0 and run the while loop between 10 to 99 if the prime loop runs firstly copy the value of the number to first and when the loop ends copy the last number to Last

Code:

Output:

Fouth task is
4)I am a two digit prime number and the sum of my digits is 10. I am also one of the factors of 57. Who am I?

My Logic:
They told only two digit so we are going to run a loop upto 99 and I created a function to find the sum of digits and when the prime number true loop starts run we are calling the function with prime number to find the sum of digits and nested if condition is check the factor for 57.

Code:

 :
Output:

Fifth task is
5)What is the smallest 5 digit number that is exactly divisible by 72 and 108?

My Logic:
As they given the smallest five digit run the loop from 10000 to 99999 and the checking the condition using if and break the loop because they asked to find first only

Code:


Output:

Last task is

6) There are four Mobile Phones in a house. At 5 a.m, all the four Mobile
Phones will ring together. Thereafter, the first one rings every 15 minutes, the second one
rings every 20 minutes, the third one rings every 25 minutes and the fourth one rings
every 30 minutes. At what time, will the four Mobile Phones ring together again?

My Logic: This task is little bit tricky compared to all and also writing code . so we have to Least common multiple for 15,20,25,30 . Least common multiple is nothing but the joining point of all number . If we find that the task is over

Code:


Output:

After 5'o clock the alarm will ring at 10'o clock.

That's all about today's task
Let's see in another blog with different tasks...

Top comments (0)