#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;
bool isprime(ll x) {
if(x == 0 || x == 1) return false;
for(ll i = 2; i * i <= x; i++) if(x % i == 0) return false;
return true;
}
ll a, b;
vi vis;
vvi adj;
vector<ll> primes, ans;
int done = 0;
void dfs(int node) {
if(done) return;
vis[node] = 1;
if(primes[node] == b) {
cout << ans.size() << endl;
for(int i : ans) cout << i << " ";
cout << endl;
done = 1;
return;
}
for(int i : adj[node]) {
ans.pub(primes[i]);
if(!vis[i]) dfs(i);
ans.pob();
if(done) return;
}
if(done) return;
}
int main() {
// freopen("INSERT_NAME_HERE.in", "r", stdin);
// freopen("INSERT_NAME_HERE.out", "w", stdout);
cin >> a >> b;
for(ll i = a - 2; i <= a + 2; i += 2) if(isprime(i)) primes.push_back(i);
for(ll i = b - 2; i <= b + 2; i += 2) if(isprime(i)) primes.push_back(i);
primes.pub(2);
sort(all(primes));
primes.erase(unique(all(primes)), primes.end());
adj.resize(primes.size());
vis.resize(primes.size(), 0);
for(int i = 0; i < primes.size(); i++) {
for(int j = i + 1; j < primes.size(); j++) {
if(isprime(primes[j] - primes[i])) {
adj[i].pub(j);
adj[j].pub(i);
}
}
}
for(int i = 0; i < primes.size(); i++) {
if(primes[i] == a) {
ans.pub(a);
dfs(i);
break;
}
}
if(!done) cout << -1 << endl;
return 0;
}
Compilation message
lutrija.cpp: In function 'int main()':
lutrija.cpp:70:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < primes.size(); i++) {
~~^~~~~~~~~~~~~~~
lutrija.cpp:71:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = i + 1; j < primes.size(); j++) {
~~^~~~~~~~~~~~~~~
lutrija.cpp:79:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < primes.size(); i++) {
~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
474 ms |
392 KB |
Integer parameter [name=arr[4]] equals to -2039078211, violates the range [1, 1000000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
462 ms |
376 KB |
Integer parameter [name=arr[1]] equals to -2145466189, violates the range [1, 1000000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
515 ms |
356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
378 ms |
380 KB |
Integer parameter [name=arr[4]] equals to -2070243847, violates the range [1, 1000000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |