Submission #491259

# Submission time Handle Problem Language Result Execution time Memory
491259 2021-12-01T07:54:11 Z Nimbostratus Lutrija (COCI19_lutrija) C++17
56 / 70
149 ms 292 KB
#include "bits/stdc++.h"
#define endl '\n'
#define int long long
const int maxn = 2e5 + 5;
const int inf = 2e9;
const int mod = 1e9 + 7;
using namespace std;
using lint = long long;
using pii = pair<int,int>;

lint a, b;
bool rev;
vector<lint> ans;

bool prime(lint x) {
	if(x <= 1)
		return false;
	for(lint i = 2; i * i <= x; i++)
		if(x % i == 0)
			return false;
	return true;
}

signed main() {
	#ifdef Local
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> a >> b;
	if(a > b) {
		swap(a, b);
		rev = true;
	}
	label:;
	ans.push_back(a);
	if(prime(b - a))
		ans.push_back(b);
	else if(a == 2) {
		if(prime(b + 2)) {
			ans.push_back(b + 2);
			ans.push_back(b);
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}
	else {
		if(!prime(a + 2)) {
			cout << -1 << endl;
			return 0;
		}
		ans.push_back(a + 2);
		a = 2;
		goto label;
	}
	if(rev)
		reverse(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for(lint i = 0; i < ans.size() - 1; i++)
		cout << ans[i] << " ";
	cout << ans.back();

}

Compilation message

lutrija.cpp: In function 'int main()':
lutrija.cpp:62:20: warning: comparison of integer expressions of different signedness: 'lint' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(lint i = 0; i < ans.size() - 1; i++)
      |                  ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 240 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 288 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 292 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 284 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct