This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b;
//ako su a i b neparni brojevi
//onda resenje moze da bude da samo dodajemo 2 do b
//ili da spustimo na 2 pa dignemo na b
//ako je a ili b jednako 2
//onda jedini nizovi koji mogu da se jave su
//2 b-2 b
//2 b+2 b
//zvanicni editorial preko bfs-a
//otkucano u vol 2
bool prime(ll x)
{
    if(x==1) return false;
    if(x==2) return true;
    for(ll i = 2;i*i<=x;i++)
       if(x%i==0) return false;
    return true;
}
bool check2(ll x,ll y)
{
    bool bo = true;
    for(ll i=x+2;i<=y && bo;i+=2) if(!prime(i)) bo=false;
    return bo;
}
bool check1(ll x,ll y)
{
    return prime(x-2) && prime(y-2);
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cerr.tie(0);
   cin >> a >> b;
   ll x = min(a,b);
   ll y = max(a,b);
   a=x;
   b=y;
   if(prime(b-a))
   {
       cout << 2  << "\n";
       cout << a << " " << b;
       return 0;
   }
   if(a%2==1 && b%2==1)
   {
       if(check1(a,b))
       {
           cout << 3 << "\n";
           cout << a << " " << 2 << " " << b << "\n";
           return 0;
       }
       if(check2(a,b))
       {
           cout << (b-a)/2 + 1 << "\n";
           for(ll i = 0;i<=(b-a)/2;i++) cout << a + 2*i << " ";
           return 0;
       }
       cout << -1;
       return 0;
   }
   else
   {
       if(prime(b+2-2))
       {
           cout << 3 << "\n";
           cout << 2 << " " << b+2 << " " << b;
           return 0;
       }
       else
       {
           if(b-2 > 2)
           {
               if(prime(b-2-2))
               {
                   cout << 3 << "\n";
                   cout << a << " " << b-2 << " " << b;
                   return 0;
               }
           }
       }
       cout << -1;
   }
   return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |