#31451: 測資517


yuxuan0912 (李毓萱Laura)


#include <iostream>
#include <cmath>

using namespace std;

bool xf(int s,int f){
    for(long j=2;j<=f;j++){
        if((s%j)==0){
            return false;    
        }
    }
    return true;
}

int main()
{
    long a,b;
    int sum=0;
    while(cin>>a>>b){
        sum=0;
            for(long i=a;i<=b;i++){
                long x;
                x= sqrt(i) + 1;
                sum+=(xf(i,x));
            }
            cout<<sum<<endl;
    }
}

正確答案說是1但我輸出0

請大大救一下 沒找到解法(已經測過a>b的確定會是0)

#31452: Re: 測資517


yuxuan0912 (李毓萱Laura)


#include
#include

using namespace std;

bool xf(int s,int f){
    for(long j=2;j<=f;j++){
        if((s%j)==0){
            return false;    
        }
    }
    return true;
}

int main()
{
    long a,b;
    int sum=0;
    while(cin>>a>>b){
        sum=0;
            for(long i=a;i<=b;i++){
                long x;
                x= sqrt(i) + 1;
                sum+=(xf(i,x));
            }
            cout<    }
}

正確答案說是1但我輸出0

請大大救一下 沒找到解法(已經測過a>b的確定會是0)


抱歉更正一下 答案說是0但我輸出1

#31469: Re: 測資517


cges30901 (cges30901)


#include
#include

using namespace std;

bool xf(int s,int f){
    for(long j=2;j<=f;j++){
        if((s%j)==0){
            return false;    
        }
    }
    return true;
}

int main()
{
    long a,b;
    int sum=0;
    while(cin>>a>>b){
        sum=0;
            for(long i=a;i<=b;i++){
                long x;
                x= sqrt(i) + 1;
                sum+=(xf(i,x));
            }
            cout<    }
}

正確答案說是1但我輸出0

請大大救一下 沒找到解法(已經測過a>b的確定會是0)


抱歉更正一下 答案說是0但我輸出1


1和2的判斷出了問題,1不是質數,2是質數