| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:请问用时很少的同志们是不是素数的判断有什么技巧?指点一下啊!会非常感激的!!!In Reply To:Re:请问用时很少的同志们是不是素数的判断有什么技巧?指点一下啊!会非常感激的!!! Posted by:xfxyjwf at 2005-03-14 19:23:03 > #include <stdio.h>
> #include <memory.h>
> bool odd[1000001];
> int main()
> {
> int i, j;
> int x;
> memset(odd, true, sizeof(odd));
> for(i = 2; i <= 500000; i++)
> {
> if(odd[i])
> {
> for(j = 2; j < 1000000/i; j++)
> {
> odd[i + j * i] = false;
> }
> }
> }
> scanf("%d", &x);
> while(x > 0)
> {
> for(i = 3; i <= x/2; i += 2)
> {
> if(odd[i] && odd[x-i])
> {
> break;
> }
> }
> printf("%d = %d + %d\n", x, i, x-i);
> scanf("%d", &x);
> }
> return 0;
> }
>
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator