Hdu2098 split prime number and

Source: Internet
Author: User

Split Prime and time limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others) Total submission (s): 20301 accepted submission (s): 8854

Problem description splits an even number into two sums of different prime numbers. How can we split them?
The input contains some positive and even numbers. The input value does not exceed 10000, And the number does not exceed 500. In case of 0, it ends.
Output corresponds to each even number. The output is split into numbers of different prime numbers, and each result occupies one row.
Sample Input
30260
 
Sample output
32
 

#include <stdio.h>#include <math.h>#define maxn 10002int prime[maxn] = {1, 1};int main(){int i, n, j, ans;n = sqrt(maxn);for(i = 2; i <= n; ++i){if(prime[i]) continue;for(j = i * i; j <= maxn; j += i)prime[j] = 1;}while(scanf("%d", &n), n){j = n >> 1; ans = 0;for(i = 2; i < j; ++i)if(!prime[i] && !prime[n - i]) ++ans;printf("%d\n", ans);}return 0;}


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.