解题思路:
注意事项:
参考代码:
#include <iostream> #include <string> #include <cstdio> #include <map> #include <set> #include <list> #include <vector> #include <cstring> #include <queue> #include <algorithm> #include <cmath> #include <cstdlib> #include <stack> #include <ctime> using namespace std; int ans[1000005]; int main(){ int arr[32000] = {1,1}; for(int j = 2;j != 32000;j++){ if(!arr[j]){ for(int k = j + j;k < 32000;k+=j) arr[k] = 1; } } vector<int> prime; for(int j = 0;j != 32000;j++) if(!arr[j]) prime.push_back(j); int l,r; while(~scanf("%d%d",&l,&r)){ memset(ans,0,sizeof(ans)); for(auto & p : prime){ for(int t = (l / p + (l % p ? 1 : 0)) * p;t <= r;t += p) if(t != p) ans[t - l] = 1; } int aans = 0; for(int j = l;j <= r;j++) if(!ans[j - l]) aans++; printf("%d\n",aans); } return 0; }
0.0分
1 人评分
母牛的故事 (C语言代码)浏览:923 |
蛇行矩阵 (C语言代码)浏览:564 |
2006年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:904 |
IP判断 (C语言代码)浏览:923 |
C语言训练-排序问题<1> (C语言代码)浏览:1351 |
C语言训练-斐波纳契数列 (C语言代码)浏览:1173 |
九宫重排 (C++代码)浏览:2160 |
回文串 (C语言代码)浏览:2858 |
上车人数 (C语言代码)浏览:781 |
【绝对值排序】 (C语言代码)浏览:821 |