#include<cstdio> #include<queue> #define N 1001 usingnamespacestd;
int prime[N]; intbfs(int s, int t); intmain() { //建質數表 bool notPrime[N] = { true, true }; int s, t, i, j; for (i = 2; i <= 32; i++) for (j = i + i; j < N; j += i) notPrime[j] = true; int cp = 0; for (i = 2; i < N; i++) if (!notPrime[i]) prime[cp++] = i;
int Case = 0; while (scanf("%d%d", &s, &t) && s&&t) { printf("Case %d: ",++Case); if (s == t) puts("0"); else printf("%d\n", bfs(s,t)); }
return0; } intbfs(int s, int t) { int count[1001] = {};//深度 queue<int> q; q.push(s);
while (!q.empty()) { int now = q.front(); q.pop(); for (int p_idx = 0; prime[p_idx] < now; p_idx++)//不包含 now 自己 { if (!(now%prime[p_idx])) { int temp = now + prime[p_idx]; if (count[temp])//已經排進去過了 continue;