답안 #221165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
221165 2020-04-09T15:45:57 Z eohomegrownapps Lutrija (COCI19_lutrija) C++14
0 / 70
5 ms 488 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

bool isPrime(ll p){
	//cout<<p<<endl;
	if (p<2){
		return false;
	}
	if (p==2){
		return true;
	}
	if (p%2==0){
		return false;
	}
	for (ll i = 3; i*i<=p; i+=2){
		if (p%i==0){
			return false;
		}
	}
	return true;
}

ll closest2(ll x){
	ll mindist = 1e9;
	ll minval = -1;
	for (ll i = x; i<=x+62; i+=2){
		if (!isPrime(i)){
			break;
		}
		if (isPrime(abs(i-2))){
			mindist=abs(i-x);
			minval=i;
			break;
		}
	}
	for (ll i = x-2; i>=max(0LL,x-62); i-=2){
		if (!isPrime(i)){
			break;
		}
		if (isPrime(abs(i-2))){
			if (abs(i-x)<mindist){
				mindist=abs(i-x);
				minval=i;
			}
			break;
		}
	}
	return minval;
}

int main(){
	ll a,b;
	cin>>a>>b;
	bool rev = false;
	//is one 2
	if (b==2){
		rev = true;
		swap(a,b);
	}
	if (a==2){
		ll c = closest2(b);
		if (c==-1){
			cout<<-1<<endl;
			return 0;
		}
		vector<ll> ans;
		ans.push_back(2);
		while (c!=b){
			ans.push_back(c);
			c+=2*((b-c)/abs(b-c));
		}
		ans.push_back(c);
		if (rev){
			reverse(ans.begin(),ans.end());
		}
		assert(ans.size()<=30);
		cout<<ans.size()<<'\n';
		for (ll i : ans){
			cout<<i<<" ";
		}cout<<'\n';
		return 0;
	}
	bool works = true;
	for (ll i = a; (i!=b&&abs(a-b)<62); i+=2*((b-a)/abs(b-a))){
		if (!isPrime(i)){
			works=false;
		}
	}
	if (works){
		vector<ll> ans;
		for (ll i = a; (i!=b&&abs(a-b)<62); i+=2*((b-a)/abs(b-a))){
			ans.push_back(i);
		}ans.push_back(b);
		assert(ans.size()<=30);
		cout<<ans.size()<<'\n';
		for (ll i : ans){
			cout<<i<<" ";
		}cout<<'\n';
		return 0;
	}

	ll x = closest2(a);
	ll y = closest2(b);
	if (x==-1||y==-1){
		cout<<-1<<'\n';
		return 0;
	}
	vector<ll> ans;
	while (a!=x){
		ans.push_back(a);
		a+=2*((x-a)/abs(x-a));
	}
	ans.push_back(a);
	ans.push_back(2);
	while (y!=b){
		ans.push_back(y);
		y+=2*((b-y)/abs(b-y));
	}
	ans.push_back(y);
	assert(ans.size()<=30);
	cout<<ans.size()<<'\n';
	for (ll i : ans){
		cout<<i<<" ";
	}cout<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 488 KB Output isn't correct
2 Halted 0 ms 0 KB -