求俄罗斯套娃素数(BFS)
求俄罗斯套娃素数(BFS)
[var1]
#pragma GCC optimize(2)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false)
#define space putchar(' ')
#define enter putchar('\n')
#define lson root<<1
#define rson root<<1|1
typedef pair PII;
const int mod=1e9+7;
const int N=2e6+10;
const int M=1e3+10;
const int inf=0x7f7f7f7f;
const int maxx=2e5+7;
const double eps=1e-6;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*(b/gcd(a,b));
}
template
void read(T &x)
{
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-')
op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op)
x = -x;
}
template
void write(T x)
{
if(x < 0)
x = -x, putchar('-');
if(x >= 10)
write(x / 10);
putchar('0' + x % 10);
}
ll qsm(int a,int b,int p)
{
ll res=1%p;
while(b)
{
if(b&1)
res=res*a%p;
a=1ll*a*a%p;
b>>=1;
}
return res;
}
bool judge(int x)
{
for(int i=2;i*i<=x;i++)
if(x%i==0)return false;
return true;
}
queue q1;
int cnt=0;
void bfs()
{
q1.push(2);
q1.push(3);
q1.push(5);
q1.push(7);
while(!q1.empty())
{
int x=q1.front();
q1.pop();
cout<
if(cnt==83)break;
for(int i=1;i<=9;i++)
{
if(judge(x*10+i))
{
q1.push(x*10+i);
}
}
}
}
int main()
{
bfs();
return 0;
}
求俄罗斯套娃素数(BFS)相关教程