| 36 | queue<int> q; |
| 37 | int d[100005]; |
| 38 | void bfs(int x) |
| 39 | { |
| 40 | q.push(x); |
| 41 | visited[x]=true; |
| 42 | d[x]=0; |
| 43 | while(!q.empty()) |
| 44 | { |
| 45 | int cur=q.front(); |
| 46 | q.pop(); |
| 47 | if(cur==k) |
| 48 | { |
| 49 | return; |
| 50 | } |
| 51 | for (int i = 0; i < r; ++i) |
| 52 | { |
| 53 | int next=(1ll*a[i]*cur)%mod1; |
| 54 | if(!visited[next]) |
| 55 | { |
| 56 | q.push(next); |
| 57 | visited[next]=true; |
| 58 | d[next]=d[cur]+1; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | int main() |
| 64 | { |
| 65 | ios_base::sync_with_stdio(false);//this works only |