俄罗斯套娃素数c语言解法,求俄罗斯套娃素数(BFS)

求俄罗斯套娃素数(BFS)

求俄罗斯套娃素数(BFS)

b3de9561239f8014467f9b72e5698cd9.png

[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)相关教程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值