做了一晚上真的心好累。。就一個錯誤怎麼都過不去。。。。
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int m,n;
int i,j,counter=2,flag=1;
cin>>m>>n;
if(m==1)
cout<<"2"<<" ";
else if(m==1&&n==1)
cout<<"2";
for(i=3;counter<=n;i++){//條件不用非得是i相關的。。
for(j=2;j<=sqrt(i)&&flag;j++){
if(i%j==0){
flag=0;
break;
}
}
if(flag)
{
if(counter>=m && counter<=n)
{
if((counter-m+1)%10==0&&counter!=n)
cout<<i<<endl;
else if(counter!=n)
cout<<i<<" ";
else
cout<<i;
}
++counter;
}
flag=1;
}
//素數是多少不知道,只知道素數的個數。從m到n個。
//1.算出所有素數 再輸出那些特定的數
//2.定義一個flag 如果整除有餘的就爲0 反之爲1
//3.定義counter 數素數的個數
}
感覺一個bug是,有一個測試用例不通過,爲什麼不能寫出來它是什麼……
不然怎麼改無從下手啊……真的這道題弄了一晚上……心好累……
明日再戰……本來想每天兩道的 發現兩道根本弄不完
寫完一道都感覺精疲力盡- -可能是我太菜了……