Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA.........??? 那位帮忙解决下!

Posted by 33p at 2009-08-14 16:51:18 on Problem 3511
#include<iostream>
#include<cmath>
#include<cstring>
#define N 10000
using namespace std;
int prime(long n)
{
    long i;
    for(i = 2; i <= sqrt(n); i++)
          if(n % i == 0)
          {
               return 0;
               break;
          }
    return 1;
}
int main()
{
    long a, b, i, j, l, k;
    long p[N];
    while(cin >> a >> b && a != -1 && b != -1)
    {
              memset(p, 0, sizeof(p));
              long x = 0, y = 0;
              for(i = a, j = 0; i <= b; i++)
              {
			   		if(i == 2)	y++;
                    if(prime(i))
                    {
                                p[j] = i;
                                j++;
                                x++;
                    }
              }
              for(k = 0; k < j; k++)
              {                     
                      if((p[k]-1) % 4 == 0)
                                  y++;
              }
              cout << a << ' ' << b << ' ' << x << ' ' << y << endl;
    }
        return 0;
}
                 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator