# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
823871 | 2023-08-13T09:09:18 Z | Sandarach151 | Lutrija (COCI19_lutrija) | C++17 | 1 ms | 320 KB |
#include<bits/stdc++.h> using namespace std; long long M; long long qexp (long long b, long long e) { //quick exponentiation (see below) if (e == 0) return 1; if (e == 1) return b%M; long long h = qexp(b, e/2); h *= h; h %= M; if (e%2 == 0) return h; return (h*b)%M; } bool isPrime(long long N) { if (N <= 1) return 0; if (N <= 3) return 1; if (N == 4) return 0; long long s = (N-1)&(1-N), d = (N-1)/s; M = N; for (long long i = 0, K = 30; i < K; ++i) { long long witness = rand()%(N-4) + 2; //generate random witness between [2, N-2] long long a = qexp(witness, d); if (a == 1 || a == N-1) continue; bool pass = 1; for (long long k = 1; k < s && pass; k<<=1) { a*=a; a%=N; if (a == N-1) pass = false; } if (pass) return 0; /* not a prime due to witness */ } return 1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); long long a, b; vector<long long> vect; cin >> a >> b; bool swapped = false; if(a==2){ swap(a, b); swapped = true; } long long tempa = a; bool res1 = true; while(!isPrime(abs(b-a))){ a+=2; if(!isPrime(a)){ res1 = false; break; } } a = tempa; bool res2 = true; while(!isPrime(abs(b-a))){ a-=2; if(!isPrime(a)){ res2 = false; break; } } if(!res1 && !res2){ cout << -1 << '\n'; } else{ if(res1){ a = tempa; vect.push_back(a); while(!isPrime(abs(b-a))){ a+=2; vect.push_back(a); } vect.push_back(b); } else{ a = tempa; vect.push_back(a); while(!isPrime(abs(b-a))){ a-=2; vect.push_back(a); } vect.push_back(b); } if(!swapped){ cout << vect.size() << '\n'; for(long long i=0; i<vect.size(); i++){ cout << vect[i] << ' '; } } else{ cout << vect.size() << '\n'; for(long long i=vect.size()-1; i>=0; i--){ cout << vect[i] << ' '; } } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 320 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 232 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 316 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |