Peter想爲他的密碼系統生成一些prime numbers
密碼系統。幫助他! 您的任務是生成兩個給定數字之間的所有素數!SPOJ上的時間超出錯誤
輸入
輸入開始的測試用例在單行(t<=10)
數噸。在下一個t行中,有兩個數字m and n (1 <= m <= n <= 1000000000, n-m<=100000)
由空格分隔。
輸出
對於每個測試實例打印所有素數p
使得m <= p <= n
,每行一個數,測試用例由空行分隔。
這裏是鏈接http://www.spoj.com/problems/PRIME1/
我想出了這個解決方案,但它顯示的時間超過了錯誤,所以我怎麼能提高呢?
#include<stdio.h>
int main()
{
int n,a,i,b;
scanf("%d",&i);
while(i>0){
scanf("%d",&a);
scanf("%d",&b);
while(a<=b){
for(n=2;n<=a;n++){
if(a%n==0)break;
}
if(a==n){
printf("%d\n",a);
}
a++;
}
i--;
printf("\n");
}
return 0;
}
鏈接到一個活的網站是沒有用的未來在這個問題上的興趣..請添加一個小提琴.. –
@JF it; 「鏈接到現場網站」? – KapilSantore