Submission #209323

# Submission time Handle Problem Language Result Execution time Memory
209323 2020-03-13T19:58:37 Z papa Lutrija (COCI19_lutrija) C++14
7 / 70
84 ms 380 KB
#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
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -