解题思路:
注意事项:
参考代码:
#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语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:625 |
弟弟的作业 (C++代码)浏览:1295 |
字符串输入输出函数 (Java代码)浏览:1437 |
P1001 (C语言代码)浏览:799 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:603 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:691 |
用筛法求之N内的素数。 (C语言代码)浏览:664 |
母牛的故事 (C语言代码)浏览:940 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:608 |
C语言程序设计教程(第三版)课后习题12.6 (C语言代码)浏览:649 |