题目链接:幸运数
解题思路:用STL的vector模拟就可以,具体看代码注释
#include<bits/stdc++.h>
#define x first
#define y second
#define mem(h) memset(h,-1,sizeof h)
#define mcp(a,b) memcpy(a,b,sizeof b)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
namespace IO{
inline LL read(){
LL o=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){o=o*10+c-'0';c=getchar();}
return o*f;
}
}using namespace IO;
const int N=1e3+7,M=2e3+7,INF=0x3f3f3f3f,mod=1e9+7,P=131;
bool st[11],bk[11];
vector<int>a;
int n,m;
void del(int i){
int v=a[i],j=a[i];
while(j<a.size())j+=v;
for(j-=v;j>=v;j-=v){
a.erase(a.begin()+j);
}
}
int main(){
cin>>m>>n;
for(int i=0;i<n;i++){
a.push_back(i);
}
del(2);
for(int i=2;i<a.size();i++){
del(i);
}
int ans=0;
for(int i=0;i<a.size();i++){
if(a[i]>m)ans++;
}
cout<<ans<<endl;
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-1188.html