Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool chk[1009];
- int total[1009];
- vector< int > prime;
- void seive()
- {
- memset(chk,0,sizeof(chk));
- chk[0]=1;
- chk[1]=0;
- prime.push_back(1);
- for(int i=2;i<=1000;i++){
- if(chk[i]){
- continue;
- }
- prime.push_back(i);
- for(int j=2;i*j<=1000;j++){
- chk[i*j]=1;
- }
- }
- int cnt=0;
- for(int i=1;i<=1000;i++){
- if(chk[i]==0){
- cnt++;
- }
- total[i]=cnt;
- }
- }
- int main()
- {
- seive();
- int n,c,i,j;
- while(cin>>n>>c){
- cout<<n<<" "<<c<<":";
- int sum = total[n];
- int x = sum/2;
- if(sum%2==0){
- i = x-c;
- j = x-1+c;
- }
- else{
- i = x-c+1;
- j= x-1+c;
- }
- if(i<0) i=0;
- if(j>=sum) j=sum-1;
- for(int z=i;z<=j;z++){
- cout<<" "<<prime[z];
- }
- cout<<"\n\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement