Question one hundred and two: Determination of prime numbers

Source: Internet
Author: User

[Plain] Description
 
For the expression n ^ 2 + n + 41, when n is an integer (including x, y) in the range of (x, y) (-39 <= x, y <= 50) to determine whether the value of this expression is a prime number.
 
Input
 
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.
 
Sample Input
 
 
0 1
0 0
 
Sample Output
 
 
OK

Description

For the expression n ^ 2 + n + 41, when n is an integer (including x, y) in the range of (x, y) (-39 <= x, y <= 50) to determine whether the value of this expression is a prime number.

Input

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.

Sample Input


0 1
0 0

Sample Output


OK
 


[Plain] # include <stdio. h>
 
Int main ()
{
Int I;
Int j;
Int n;
Int x;
Int y;
Int flag;
Int mark;
 
While (scanf ("% d", & x, & y )! = EOF, x! = 0 | y! = 0)
{
Mark = 1;
Flag = 1;
For (I = x; I <= y; I ++)
{
N = I * I + 41;
For (j = 2; j <= n/2; j ++)
{
If (n % j = 0)
{
Flag = 0;
Break;
}
}
If (flag = 0)
{
Mark = 0;
Break;
}

}
If (mark)
{
Printf ("OK \ n ");
}
Else
{
Printf ("Sorry \ n ");
}
}
 
Return 0;
}

# Include <stdio. h>

Int main ()
{
Int I;
Int j;
Int n;
Int x;
Int y;
Int flag;
Int mark;

While (scanf ("% d", & x, & y )! = EOF, x! = 0 | y! = 0)
{
Mark = 1;
Flag = 1;
For (I = x; I <= y; I ++)
{
N = I * I + 41;
For (j = 2; j <= n/2; j ++)
{
If (n % j = 0)
{
Flag = 0;
Break;
}
}
If (flag = 0)
{
Mark = 0;
Break;
}

}
If (mark)
{
Printf ("OK \ n ");
}
Else
{
Printf ("Sorry \ n ");
}
}

Return 0;
}

 


 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.