First-time blog, blog
This is my first time using a blog. I am not very familiar with it. The original intention of creating this blog is to learn from and make progress together with like-minded people. I am now studying the C language. I will share some experiences or skills with you.
The following is a question about prime numbers:
For the expression n ^ 2 + n + 41, when n is in the range of (x, y), an integer (including x and y) is obtained) (-39 <= x <y <= 50), determines whether the value of this expression is a prime number.
There are multiple groups of Input data. Each group occupies one row and consists of two integers x and y. When x = 0 and y = 0, the Input is complete and the row is not processed.
Output
For values in each given range, if the expression value is a prime number, "OK" is output; otherwise, "Sorry" is output, and each group of output occupies one row. Answer:
# Include <stdio. h>
Int main ()
{
Int x, y, I, j;
While (scanf ("% d", & x, & y) & (x | y ))
{
Int sum, m = 0;
For (j = x; j <= y; j ++)
{
Sum = j * j + 41;
For (I = 2; I <sum; I ++)
{
If (sum % I = 0)
{
M = 1;
Break;
}
}
}
If (m = 0) printf ("OK \ n ");
Else printf ("Sorry \ n ");
}
Return 0;
}
TIPS: & (x! = 0 | y! = 0) indicates that neither x nor y is 0.