解题思路:
注意事项:
参考代码:
#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 人评分
不会做的浏览:917 |
A+B for Input-Output Practice (II) (C语言代码)浏览:1005 |
C语言训练-大、小写问题 (C语言代码)浏览:617 |
淘淘的名单 (C语言代码)浏览:1114 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:942 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:332 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:1079 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:1929 |
循环入门练习5 (C语言代码)浏览:856 |
时间转换 (C语言代码)浏览:647 |