find out the 6-th Monisen number Answer

In this article i am gone to share How you can get 3/3 Points in Data Processing Using Python Week 1 Assignment with you..| Programming Assignment: find out the 6-th Monisen number Answer 

Assignment Question

Write a program to find the 6-th Monisen number.

Classic Programming Question: find the n-th Monisen number. A number M is a Monisen number if M=2P-1 and both M and P are prime numbers. For example, if P=5, M=2P-1=31, 5 and 31 are both prime numbers, so 31 is a Monisen number.

Put the 6-th Monisen number into a single text file and submit online.

My Score Proof

Follow My Step to achieve 3/3 Score

Step 1) Copy Python Code: scroll the page at bottom you get it

Step 2) Run this Code on any online or offline Python Compiler for ex: Go to this link

Step 3) Copy the output Answer

Note: In my Case i have to submit 6-th Monisen number into a single text file | Maybe in your case you got some other number, so please check first..

Create a Text File

  1. Copy Last output number: 131071
  2. Create a file give any name text file — for example: monisen.txt
  3. Paste your output value in a file: 131071
  4. Save your File and upload it..

Write a program to find the 6-th Monisen number.

import math


def is_monisen_number(value):
    log2 = int(math.log2(value + 1))
    return 2**log2 == value + 1 and log2 in PRIME_NUMBERS

def is_prime_number(value):
    stop_guard = int(math.sqrt(value))
    for p_num in PRIME_NUMBERS:
        if value % p_num == 0:
        elif p_num > stop_guard:  # prime found
            return True
        return True
    return False

def get_monisen_numbers(count):
    start = 2
    monisen_numbers = []

    while True:
        if len(monisen_numbers) == count:
            return monisen_numbers

        if is_prime_number(start):
            if is_monisen_number(start):
        start += 1

if __name__ == '__main__':
    count = int(input('Please input the {n}th number (n > 6 would cost very long time): '))

I hope this article solve your problem: if you get any error please comment..


Leave a Comment