First-time blog, blog

Source: Internet
Author: User

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.

 

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.