2
The smallest m
such that n · m + 1
don’t be a cousin.
Example:
For the first example, 3 · 1 + 1 = 4
, the exit will be 1
.
For the second example, 4 · 1 + 1 = 5
, we can’t print 1
because 5
is cousin.
However, m = 2
is all right, since 4 · 2 + 1 = 9
, that is not cousin.
For the third example, 10 · 2 + 1 = 21
, print 2
.
I wrote the following code but this giving error:
n=int(input())
z=2
m=1
div=0
x =(n*m+1)
if n>=1 and n<=1000:
while z<=x-1:
if x%z==0:
div=div+1
z=z+1
if div==0:
m=m+1
x=n*m+1
if x==1 or x==2 or x==3:
m=m+1
x=n*m+1
print(m)
I stalled in trying to help you in math because, for example, I didn’t understand the role of the 'z' variable and why it was initialized with the value 2. It would be nice if you included some comments in your code explaining what you are doing.
– Éder Garcia
he used the variable
z
just to symbolize the 2 that in the case is the condition of validation of prime numbers, which I found a little unnecessary to create a variable for a constant.– WhoisMatt
Ah, I get it, I’ll try to figure out... hug!
– Éder Garcia
As you can see I already solved, but it’s okay if you want to too! :)
– WhoisMatt