Language: Java

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,n) for(int i = (a);i < (n);i++)
const int MAX_E = 1e3 + 3;
const int START = MAX_E / 2;
const int N = 1e6 + 3;
const int INF = 1e9;
int p[N+1];
void e(){
  fill(p,p+N,1);
  p[0] = p[1] = 0;
  for(int i = 2;i*i<=N;i++)
    if(p[i] == 1)for(int j = i*i;j<=N;j+=i)p[j] = 0;
}

map<pair<int,int> ,int> mp;

inline pair<int,int> pmax(pair<int,int> a, pair<int,int> b,int x,int y){
  // a is pre
  if(p[mp[make_pair(x,y)]]){
    a.first++;
    b.second = mp[make_pair(x,y)];
    a.second = mp[make_pair(x,y)];
    if(a.first > b.first)return a;
    else return b;
  }else{
    if(a.first > b.first)return a;
    else return b;
  }
}

int main(){
  int n,m;

  int dx[4] = {1,0,-1,0};
  int dy[4] = {0,-1,0,1};
  e();
  pair<int,int> co[MAX_E][MAX_E];// n, is prime
  pair<int,int> dp[MAX_E][MAX_E];// first is num, second is prime
  int rx =START,lx = START,uy = START,ly = START;
  int x = START,y = START,mode = 0;
  FOR(i,1,N){
    mp[make_pair(x,y)] = i;
    x += dx[mode];
      y += dy[mode];
      if(mode == 0 && x > rx){rx = x;mode++;}
      if(mode == 1 && y > uy){uy = y;mode++;}
      if(mode == 2 && x < lx){lx = x;mode++;}
      if(mode == 3 && y < ly){ly = y;mode++;}
  }


  
  while(cin>>n>>m,n){
    int rx =START,lx = START,uy = START,ly = START;

    int x = START,y = START,mode = 0;
    int sx,sy;
    fill(co[0],co[MAX_E],make_pair(INF,0));
    FOR(i,1,n+1){
      if(i == m){//get start
      sx = x,sy = y;
      }

      co[MAX_E/2 + x][MAX_E/2 + y] = make_pair(i,p[i]);
      x += dx[mode];
      y += dy[mode];
      if(mode == 0 && x > rx){rx = x;mode++;}
      if(mode == 1 && y > uy){uy = y;mode++;}
      if(mode == 2 && x < lx){lx = x;mode++;}
      if(mode == 3 && y < ly){ly = y;mode++;}
    }

    int prelx = x,prerx = x;
    int nowlx = x,nowrx = x;
    sy--;
    for(;sy >= ly;sy--){
      if(co[nowlx][nowrx].first != INF)nowlx--;
      if(co[nowrx][nowrx].first != INF)nowrx++;
      for(int i  = nowlx; i <= nowrx;i++){
        if(i < prerx) dp[i][sy] = pmax(dp[i][sy],dp[i][sy],i,sy);
        if(i <= prerx && i >= prelx)dp[i][sy] = pmax(dp[i][sy+1], dp[i][sy],i,sy);
        if(i > prelx)dp[i][sy] = pmax(dp[i-1][sy+1], dp[i][sy],i,sy);
      }
      prelx = nowlx;
      prerx = nowrx;
    }
    pair<int,int> ans = make_pair(0,0);

    rx =START,lx = START,uy = START,ly = START;
    x = START,y = START,mode = 0;
    FOR(i,1,n+1){
      if(dp[x][y].first > ans.first)ans = dp[x][y];
      if(dp[x][y].first == ans.first && dp[x][y].second > ans.second)ans = dp[x][y];
    x += dx[mode];
      y += dy[mode];
      if(mode == 0 && x > rx){rx = x;mode++;}
      if(mode == 1 && y > uy){uy = y;mode++;}
      if(mode == 2 && x < lx){lx = x;mode++;}
      if(mode == 3 && y < ly){ly = y;mode++;}
    }
    cout << ans.first << ' ' << ans.second << endl;
  }
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <iostream>
^
Main.java:2: error: illegal character: '#'
#include <vector>
^
Main.java:3: error: illegal character: '#'
#include <algorithm>
^
Main.java:4: error: illegal character: '#'
#include <map>
^
Main.java:7: error: illegal character: '#'
#define REP(i,n) for(int i = 0;i < (n);i++)
^
Main.java:7: error: class, interface, enum, or record expected
#define REP(i,n) for(int i = 0;i < (n);i++)
        ^
Main.java:7: error: class, interface, enum, or record expected
#define REP(i,n) for(int i = 0;i < (n);i++)
                               ^
Main.java:7: error: class, interface, enum, or record expected
#define REP(i,n) for(int i = 0;i < (n);i++)
                                       ^
Main.java:8: error: illegal character: '#'
#define FOR(i,a,n) for(int i = (a);i < (n);i++)
^
Main.java:8: error: class, interface, enum, or record expected
#define FOR(i,a,n) for(int i = (a);i < (n);i++)
                                   ^
Main.java:8: error: class, interface, enum, or record expected
#define FOR(i,a,n) for(int i = (a);i < (n);i++)
                                           ^
Main.java:10: error: class, interface, enum, or record expected
const int START = MAX_E / 2;
^
Main.java:11: error: class, interface, enum, or record expected
const int N = 1e6 + 3;
^
Main.java:12: error: class, interface, enum, or record expected
const int INF = 1e9;
^
Main.java:13: error: class, interface, enum, or record expected
int p[N+1];
^
Main.java:14: error: unnamed classes are a preview feature and are disabled by default.
void e(){
^
  (use --enable-preview to enable unnamed classes)
Main.java:23: error: class, interface, enum, or record expected
inline pair<int,int> pmax(pair<int,int> a, pair<int,int> b,int x,int y){
^
Main.java:27: error: class, interface, enum, or record expected
    b.second = mp[make_pair(x,y)];
    ^
Main.java:28: error: class, interface, enum, or record expected
    a.second = mp[make_pair(x,y)];
    ^
Main.java:29: error: class, interface, enum, or record expected
    if(a.first > b.first)return a;
    ^
Main.java:30: error: class, interface, enum, or record expected
    else return b;
    ^
Main.java:31: error: class, interface, enum, or record expected
  }else{
  ^
Main.java:33: error: class, interface, enum, or record expected
    else return b;
    ^
Main.java:34: error: class, interface, enum, or record expected
  }
  ^
Main.java:40: error: class, interface, enum, or record expected
  int dx[4] = {1,0,-1,0};
  ^
Main.java:41: error: class, interface, enum, or record expected
  int dy[4] = {0,-1,0,1};
  ^
Main.java:42: error: class, interface, enum, or record expected
  e();
  ^
Main.java:43: error: class, interface, enum, or record expected
  pair<int,int> co[MAX_E][MAX_E];// n, is prime
  ^
Main.java:44: error: class, interface, enum, or record expected
  pair<int,int> dp[MAX_E][MAX_E];// first is num, second is prime
  ^
Main.java:47: error: class, interface, enum, or record expected
  FOR(i,1,N){
  ^
Main.java:49: error: class, interface, enum, or record expected
    x += dx[mode];
    ^
Main.java:50: error: class, interface, enum, or record expected
      y += dy[mode];
      ^
Main.java:51: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
      ^
Main.java:51: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
                                     ^
Main.java:51: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
                                            ^
Main.java:52: error: class, interface, enum, or record expected
      if(mode == 1 && y > uy){uy = y;mode++;}
                                     ^
Main.java:52: error: class, interface, enum, or record expected
      if(mode == 1 && y > uy){uy = y;mode++;}
                                            ^
Main.java:53: error: class, interface, enum, or record expected
      if(mode == 2 && x < lx){lx = x;mode++;}
                                     ^
Main.java:53: error: class, interface, enum, or record expected
      if(mode == 2 && x < lx){lx = x;mode++;}
                                            ^
Main.java:54: error: class, interface, enum, or record expected
      if(mode == 3 && y < ly){ly = y;mode++;}
                                     ^
Main.java:54: error: class, interface, enum, or record expected
      if(mode == 3 && y < ly){ly = y;mode++;}
                                            ^
Main.java:63: error: class, interface, enum, or record expected
    int sx,sy;
    ^
Main.java:64: error: class, interface, enum, or record expected
    fill(co[0],co[MAX_E],make_pair(INF,0));
    ^
Main.java:65: error: class, interface, enum, or record expected
    FOR(i,1,n+1){
    ^
Main.java:68: error: class, interface, enum, or record expected
      }
      ^
Main.java:71: error: class, interface, enum, or record expected
      x += dx[mode];
      ^
Main.java:72: error: class, interface, enum, or record expected
      y += dy[mode];
      ^
Main.java:73: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
      ^
Main.java:73: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
                                     ^
Main.java:73: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
                                            ^
Main.java:74: error: class, interface, enum, or record expected
      if(mode == 1 && y > uy){uy = y;mode++;}
                                     ^
Main.java:74: error: class, interface, enum, or record expected
      if(mode == 1 && y > uy){uy = y;mode++;}
                                            ^
Main.java:75: error: class, interface, enum, or record expected
      if(mode == 2 && x < lx){lx = x;mode++;}
                                     ^
Main.java:75: error: class, interface, enum, or record expected
      if(mode == 2 && x < lx){lx = x;mode++;}
                                            ^
Main.java:76: error: class, interface, enum, or record expected
      if(mode == 3 && y < ly){ly = y;mode++;}
                                     ^
Main.java:76: error: class, interface, enum, or record expected
      if(mode == 3 && y < ly){ly = y;mode++;}
                                            ^
Main.java:81: error: class, interface, enum, or record expected
    sy--;
    ^
Main.java:82: error: class, interface, enum, or record expected
    for(;sy >= ly;sy--){
    ^
Main.java:82: error: class, interface, enum, or record expected
    for(;sy >= ly;sy--){
         ^
Main.java:82: error: class, interface, enum, or record expected
    for(;sy >= ly;sy--){
                  ^
Main.java:84: error: class, interface, enum, or record expected
      if(co[nowrx][nowrx].first != INF)nowrx++;
      ^
Main.java:85: error: class, interface, enum, or record expected
      for(int i  = nowlx; i <= nowrx;i++){
      ^
Main.java:85: error: class, interface, enum, or record expected
      for(int i  = nowlx; i <= nowrx;i++){
                          ^
Main.java:85: error: class, interface, enum, or record expected
      for(int i  = nowlx; i <= nowrx;i++){
                                     ^
Main.java:87: error: class, interface, enum, or record expected
        if(i <= prerx && i >= prelx)dp[i][sy] = pmax(dp[i][sy+1], dp[i][sy],i,sy);
        ^
Main.java:88: error: class, interface, enum, or record expected
        if(i > prelx)dp[i][sy] = pmax(dp[i-1][sy+1], dp[i][sy],i,sy);
        ^
Main.java:89: error: class, interface, enum, or record expected
      }
      ^
Main.java:91: error: class, interface, enum, or record expected
      prerx = nowrx;
      ^
Main.java:92: error: class, interface, enum, or record expected
    }
    ^
Main.java:95: error: class, interface, enum, or record expected
    rx =START,lx = START,uy = START,ly = START;
    ^
Main.java:96: error: class, interface, enum, or record expected
    x = START,y = START,mode = 0;
    ^
Main.java:97: error: class, interface, enum, or record expected
    FOR(i,1,n+1){
    ^
Main.java:99: error: class, interface, enum, or record expected
      if(dp[x][y].first == ans.first && dp[x][y].second > ans.second)ans = dp[x][y];
      ^
Main.java:100: error: class, interface, enum, or record expected
    x += dx[mode];
    ^
Main.java:101: error: class, interface, enum, or record expected
      y += dy[mode];
      ^
Main.java:102: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
      ^
Main.java:102: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
                                     ^
Main.java:102: error: class, interface, enum, or record expected
      if(mode == 0 && x > rx){rx = x;mode++;}
                                            ^
Main.java:103: error: class, interface, enum, or record expected
      if(mode == 1 && y > uy){uy = y;mode++;}
                                     ^
Main.java:103: error: class, interface, enum, or record expected
      if(mode == 1 && y > uy){uy = y;mode++;}
                                            ^
Main.java:104: error: class, interface, enum, or record expected
      if(mode == 2 && x < lx){lx = x;mode++;}
                                     ^
Main.java:104: error: class, interface, enum, or record expected
      if(mode == 2 && x < lx){lx = x;mode++;}
                                            ^
Main.java:105: error: class, interface, enum, or record expected
      if(mode == 3 && y < ly){ly = y;mode++;}
                                     ^
Main.java:105: error: class, interface, enum, or record expected
      if(mode == 3 && y < ly){ly = y;mode++;}
                                            ^
Main.java:108: error: class, interface, enum, or record expected
  }
  ^
85 errors