Knowee
Questions
Features
Study Tools

erzy, a devoted mathematician, is looking to develop a program that addresses a unique challenge involving prime numbers and 2D arrays.The objective of this program is to efficiently identify prime numbers within a 2D array and calculate their cumulative sum.The program will include two key functions:isPrime(num): This function will assess whether a given integer num is a prime number.sumOfPrimes(rows, cols, arr): This function will calculate and return the sum of all prime numbers found within a 2D array arr, which has dimensions specified by rows and cols. Input format :The first line of input consists of two integers r and c, representing the number of rows and columns in the 2D array.The next r lines of input consist of c integers each, separated by space, representing the elements of the 2D array.Output format :The output displays a single integer, representing the sum of all prime numbers in the given 2D array.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ r , c ≤ 101 ≤ elements ≤ 100Sample test cases :Input 1 :2 32 3 76 9 8Output 1 :12Input 2 :3 42 3 4 57 8 9 1011 12 13 14Output 2 :41Input 3 :5 52 3 4 5 96 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25Output 3 :100Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0

Question

erzy, a devoted mathematician, is looking to develop a program that addresses a unique challenge involving prime numbers and 2D arrays.The objective of this program is to efficiently identify prime numbers within a 2D array and calculate their cumulative sum.The program will include two key functions:isPrime(num): This function will assess whether a given integer num is a prime number.sumOfPrimes(rows, cols, arr): This function will calculate and return the sum of all prime numbers found within a 2D array arr, which has dimensions specified by rows and cols. Input format :The first line of input consists of two integers r and c, representing the number of rows and columns in the 2D array.The next r lines of input consist of c integers each, separated by space, representing the elements of the 2D array.Output format :The output displays a single integer, representing the sum of all prime numbers in the given 2D array.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ r , c ≤ 101 ≤ elements ≤ 100Sample test cases :Input 1 :2 32 3 76 9 8Output 1 :12Input 2 :3 42 3 4 57 8 9 1011 12 13 14Output 2 :41Input 3 :5 52 3 4 5 96 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25Output 3 :100Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python solution for the problem:

def isPrime(num):
    if num <= 1:
        return False
    if num == 2:
        return True
    if num % 2 == 0:
        return False
    for i in range(3, int(num**0.5)+1, 2):
        if num % i == 0:
            return False
    return True

def

Similar Questions

Single File Programming QuestionProblem statementJerzy, a devoted mathematician, is looking to develop a program that addresses a unique challenge involving prime numbers and 2D arrays.The objective of this program is to efficiently identify prime numbers within a 2D array and calculate their cumulative sum.The program will include two key functions:isPrime(num): This function will assess whether a given integer num is a prime number.sumOfPrimes(rows, cols, arr): This function will calculate and return the sum of all prime numbers found within a 2D array arr, which has dimensions specified by rows and cols. Input format :The first line of input consists of two integers r and c, representing the number of rows and columns in the 2D array.The next r lines of input consist of c integers each, separated by space, representing the elements of the 2D array.Output format :The output displays a single integer, representing the sum of all prime numbers in the given 2D array.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ r , c ≤ 101 ≤ elements ≤ 100Sample test cases :Input 1 :2 32 3 76 9 8Output 1 :12Input 2 :3 42 3 4 57 8 9 1011 12 13 14Output 2 :41Input 3 :5 52 3 4 5 96 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25Output 3 :100Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Write a Program to Find the average of all Prime Numbers from a Given Array?

In a mathematical exploration, Alex wants to find the greatest prime divisor of a given positive integer. Create a program that accomplishes this task where Alex has a positive integer, represented as a long long int. The program should find and display the greatest prime divisor of this integer.Write a program that displays the greatest prime divisor for various positive integers.Input format :The input consists of a long long integer n, representing the encryption number.Output format :The output prints the greatest prime divisor as a long long integer.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the given test cases fall under the following constraints:1 ≤ n ≤ 100

Anna is working on a program to find common factors of two unsigned integers. Design a program that:Takes two unsigned integers: n1 and n2, as input.Identifies and prints all common factors of these numbers.

An algorithm returns one of five prime numbers using a zero-indexed array to store the numbers.01 function ReturnPrime(x)02 prime = [9369319,2521008887,1442968193,10619863,6692367337]03 c = 004 for i = 1 to x05 if c > prime.length -1 then06 c = 007 endif08 p = prime[c]09 c = c + 110 next i11 return p12 endfunctionRewrite the function ReturnPrime to make it more efficient.

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.