解题思路:
注意事项:
参考代码:
#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语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:561 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:611 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:1514 |
Pascal三角 (C语言代码)格式错误浏览:516 |
【蟠桃记】 (C语言代码)浏览:664 |
a+b浏览:432 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:561 |
DNA (C语言代码)浏览:745 |
C语言训练-亲密数 (C语言描述,反正怎么都能对)浏览:2156 |
GC的苦恼 (C语言代码)浏览:618 |