#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common
typedef long long i64,ll;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(l);i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}


class Task{
public:
	int y,x;
	int c,M;
	Task(int y,int x,int c,int M):y(y),x(x),c(c),M(M){}
	bool operator < (const Task& r) const{
		if(c!=r.c)return c<r.c;
		return M<r.M;
	}
};
int INF=1<<28;


	int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};


class Main{
public:
	
	int m,n;
	bool input(){
		cin >> m >> n;if(m==0 && n==0)return false;
		return true;
	}

	vector<bool> sieve(const int M){
		vector<bool> isPrime(M);
		for(int i=2;i<M;i++) isPrime[i] = true;
		for(int i=2;i*i < M;i++){
			if(! isPrime[i]) continue;
			for(int j=i*i;j<M;j+=i)isPrime[j] = false;
		}
		return isPrime;
	}

	bool comp(int c1,int M1,int c2,int M2){
		if(c1!=c2)return c1<c2;
		return M1<M2;
	}


	void run(){
		//prime
		vector<bool> ps=sieve(4000050);

		vector<vector<int>> board(2100,vector<int>(2100));
		vector<int> xs(4000050),ys(4000050);

		int y=1050,x=1050,v=1;
		board[y][x]=v;xs[v]=x;ys[v]=y;v++;
		int d=1,dir=0;
		while(v<3000050){

			REP(_d,d){
				y+=dy[dir];x+=dx[dir];
				board[y][x]=v;xs[v]=x;ys[v]=y;v++;
			}
			dir=(dir-1+4)%4;
			if(dir%2==0)d++;
		}

		while(input()){
			vector<vector<pair<int,int>>> dp(2100,vector<pair<int,int>>(2100,make_pair(-INF,-INF)));


			pair<int,int> res=make_pair(0,0);

			int pc=0,pM=0;
			if(ps[n])pc++,pM=n;
			dp[ys[n]][xs[n]]=make_pair(pc,pM);
			for(int y=ys[n];y<2100;y++){
				REP(x,2100){
					for(int dx=-1;dx<=1;dx++){//move
						int nx=x+dx,ny=y+1;if(!IN(0,ny,2100)|| !IN(0,nx,2100))continue;
						int nv=board[ny][nx];if(!(nv<=m))continue;
						int nc=dp[y][x].first,nM=dp[y][x].second;
						if(ps[nv])nc++,nM=nv;
						if(comp(dp[ny][nx].first,dp[ny][nx].second,nc,nM)){
							dp[ny][nx]=make_pair(nc, nM);
						}
					}

					//end
					bool end=true;
					for(int dx=-1;dx<=1;dx++){
						int nx=x+dx,ny=y+1;if(!IN(0,ny,2100)|| !IN(0,nx,2100))continue;
						int nv=board[ny][nx];if(!(nv<=m))continue;
						end=false;
					}
					if(end)res=max(dp[y][x],res);
				}
			}
			cout <<res.first <<" "<<res.second<<endl;
		}
	}
};

 int main(){
	//ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

Measured memory_bytes: 84796