Write a Python (or R) program that asks the user to enter an integer (X), then: Determines if X is prime or not If X is not prime, compute and print the factors of that integer X Evaluate and print the equation Y=8X²+ 1, for X values from -5 to 5 using the range function and for loop
Answers
Answer:
The algorithm can be improved further by observing that all primes are of the form 6k ± 1, with the exception of 2 and 3. This is because all integers can be expressed as (6k + i) for some integer k and for i = -1, 0, 1, 2, 3, or 4; 2 divides (6k + 0), (6k + 2), (6k + 4); and 3 divides (6k + 3). So a more efficient method is to test if n is divisible by 2 or 3, then to check through all the numbers of form 6k ± 1.
mark as brain t
Answer:
Explanation:
Python is a computer programming language that is frequently used to create software and websites, automate processes, and perform data analysis. Because Python is a general-purpose language, it may be used to develop a wide range of programmes and isn't tailored for any particular issues.
Python is frequently used to create websites and applications, automate tasks, analyse data, and visualise data. Many non-programmers, including accountants and scientists, have adopted Python because it's reasonably simple to learn and can be used for a number of common activities like managing finances.
I have written the code of the given question in python programming language.
Code :
x=int(input("Enter an integer:"))
prime=True
for i in range(2,x):
if(x%i==0):
prime=False
break
if(prime):
print("it is a prime")
else:
print("it is not a prime factors:")
for i in range(2,x):
if(x%i==0):
prime=False
print(i)
for x in range(-5,5+1,1):
print(8*(x**2)+1)
Output :
#SPJ2