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

SB题目……详见代码

Posted by buaabarty at 2011-07-21 15:32:26 on Problem 3978
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define N 1000000
using namespace std;
bool isprime(int x)
{
    //if (x < 0) x = -x;
    if (x <= 1) return false;
    if (x == 2) return true;
    for (int i = 2; i <= (int)(sqrt((double)x) + 1); ++i)
        if (x % i == 0) return false;
    return true;
}
int main()
{
    int x, y;
    while (scanf("%d%d", &x, &y))
    {
        if ((x == -1) && (y == -1)) break;
        int sum = 0;
        for (int i = x; i <= y; ++i)
            if (isprime(i)) sum++;
        printf("%d\n", sum);
    }
    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