poj3126 筛素数+bfs

时间:2023-03-09 13:06:40
poj3126 筛素数+bfs
 //Accepted    212 KB    16 ms
 //筛素数+bfs
 #include <cstdio>
 #include <cstring>
 #include <iostream>
 #include <queue>
 using namespace std;
 ;
 ;
 bool pri[imax_n];
 bool vis[imax_n];
 void prime()
 {
     ;i<imax_n;i++)
     {
         for (int j=i*i;j<imax_n;j+=i)
         {
             pri[j]=;
         }
     }
     pri[]=pri[]=;
 }
 queue<int > q,step;
 int ans;
 void bfs(int s,int e)
 {
     while (!q.empty()) q.pop();
     while (!step.empty()) step.pop();
     memset(vis,false,sizeof(vis));
     ans=inf;
     q.push(s);
     vis[s]=true;
     step.push();
     while (!q.empty())
     {
         int x=q.front();
         q.pop();
         int temp_step=step.front();
         step.pop();
         if (x==e)
         {
             ans=temp_step;
             return ;
         }
         ;
         ;i<=;i++)
         {
             ;
              && !vis[nx])
             {
                 q.push(nx);
                 step.push(temp_step+);
                 vis[nx]=true;
             }
         }
         t=(x%)%+x/*;
         ;i<=;i++)
         {
             ;
              && !vis[nx])
             {
                 q.push(nx);
                 step.push(temp_step+);
                 vis[nx]=true;
             }
         }
         t=x/*+x%%;
         ;i<=;i++)
         {
             ;
              && !vis[nx])
             {
                 q.push(nx);
                 step.push(temp_step+);
                 vis[nx]=true;
             }
         }
         t=x/*;
         ;i<=;i+=)
         {
             int nx=t+i;
              && !vis[nx])
             {
                 q.push(nx);
                 step.push(temp_step+);
                 vis[nx]=true;
             }
         }
     }
 }
 int main()
 {
     prime();
     int T;
     scanf("%d",&T);
     while (T--)
     {
         int a,b;
         scanf("%d%d",&a,&b);
         bfs(a,b);
         if (ans==inf)
         printf("Impossible\n");
         else
         printf("%d\n",ans);
     }
     ;
 }