Knowee
Questions
Features
Study Tools

Unique PrimeSend FeedbackProblem Statement:Write a program that takes a list of numbers as input and prints all the unique prime numbers from the list in a single line. The program should contain two functions: one to check if a number is prime and another to return the unique values from the list.Input:A list of numbers.Output:The function should return a single line containing the unique prime numbers from the list.Sample Input:[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13]Sample Output:2 3 5 7 11 13

Question

Unique PrimeSend FeedbackProblem Statement:Write a program that takes a list of numbers as input and prints all the unique prime numbers from the list in a single line. The program should contain two functions: one to check if a number is prime and another to return the unique values from the list.Input:A list of numbers.Output:The function should return a single line containing the unique prime numbers from the list.Sample Input:[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13]Sample Output:2 3 5 7 11 13

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

Solution

Sure, here is a Python solution for the problem:

def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def unique_primes(lst):
    unique_nums = list(set(lst))
    primes = [num for num in unique_nums if is_prime(num)]
    return primes

lst = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13]
print(*unique_primes(lst))

In this solution, we first define a function is_prime(n) to check if a number n is prime. Then we define another function unique_primes(lst) to get the unique prime numbers from the list lst. In this function, we first get the unique numbers from the list using set(), then we use list comprehension to get the prime numbers from these unique numbers. Finally, we print the unique prime numbers.

This problem has been solved

Similar Questions

Create a Python function that takes a list of integers as input andreturns a new list containing only the prime numbers from the input list.Provide a clear explanation of your implementation and include a test case.

The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.OutputFor every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.ExampleInput:21 103 5Output:235735

write a c program to print unique prime numbers in array

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!InputThe input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.OutputFor every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.ExampleInput:21 103 5Output:235735Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)InformationAfter cluster change, please consider PRINT as a more challenging problem.

Problem Statement:Find whether the given number is prime or not.Input Format:Accept an integer as inputOutput Format:Print the output as "Prime Number" or "Not a Prime Number"Constraints:1 <= INPUT <=10^15Sample Input 1:31Sample Output 1:Prime NumberSample Input 2:2Sample Output 2:Prime NumberSample Input 3:15Sample Output 3:Not a Prime Number

1/3

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.