Borrar filtros
Borrar filtros

how to generate two primo numbers?

1 visualización (últimos 30 días)
shulei xiong
shulei xiong el 16 de Mzo. de 2019
Respondida: Naman Bhaia el 19 de Mzo. de 2019
HI,im trying to generate two primo numbers p1 and p2.
input is M,Where it is an integer,and M/2<p1,p2<M,
p=randi([M./2,M],1);
Next, what should I do? ,could you help me?

Respuestas (1)

Naman Bhaia
Naman Bhaia el 19 de Mzo. de 2019
Hey Shulei,
I am assuming you wanted two prime numbers and with the following conditions:
  1. M/2<p1<M
  2. 2<p2<M
I suggest you use the primes() function to generate a vector of prime numbers upto M and then you write a simple code to choose your p1 and p2 from the vector according to the conditions.

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by