답안 #250649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250649 2020-07-18T15:08:06 Z REALITYNB Lutrija (COCI19_lutrija) C++14
42 / 70
2000 ms 256 KB
#include <bits/stdc++.h> 
bool check(int i){
	if(i-1==0){
		return 0 ; 
	}
		bool prime= 1 ; 
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				prime = 0; 
			}
		}
		return prime ;  
}
using namespace std; 
signed main(){
	int a , b ; 
	cin>>a>>b ; 
	if(abs(b-a)==2){
		cout << 2 << endl << a << " "<< b  ; 
		return 0  ; 
	}
	if(a>2&&b>2){
		if(check(a-2)){
			if(check(b-2)){
				cout << 3 << endl ; 
				cout << a << " " << 2 << " " << b  ; 
				return 0 ; 
			}
			if(check(b+2)){
				cout << 4 << endl ;
				cout << a << " " << 2 << " " << b+2 <<  " " << b  ; 
				return 0 ; 
			}
		}
		if(check(a+2)){
			if(check(b-2)){
				cout << 4 << endl ; 
				cout << a << " " << a+2 << " " << 2 << " " << b  ; 
				return 0  ; 
			}
			if(check(b+2)){
				cout << 5 << endl ; 
				cout << a << " " << a+2 << " " << 2 << " " << b+2 << " " << b  ; 
				return 0 ; 
			}
		}
		int flg = 0 ; 
		if(a>b){
			swap(a,b) ; 
			flg = 1 ; 
		}
		vector<int> ans ;
		ans.push_back(a) ;  
		while(a!=b){
			if((int)(ans.size())>30){
					cout << -1  ; 
					return 0 ; 
			}
			a+=2 ; 
			ans.push_back(a) ; 
			if(check(a)==0){
				cout << -1 ; 
				return 0 ; 
			}
		}
		if((int)(ans.size())>30){
				cout << -1  ; 
				return 0 ; 
		}
		if(flg) reverse(ans.begin(),ans.end()) ; 
		cout <<  ans.size() << endl  ; 
		for(int& x :ans) cout << x << (x!=ans.back()?" ":"")  ; 
		return 0 ; 
	}
	if(check(abs(a-b))){
		cout << 2 << endl ; 
		cout << a  <<  " " << b  ; 
		return 0  ; 
	}
	if(check(max(a,b)+2)){
		cout << 3 << endl ; 
		cout << a <<  " " << max(a,b)+2 << " " <<  b ; 
		return 0 ;                
	}
	cout << -1 ; 
	return  0 ; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 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 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 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 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2091 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2084 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2087 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -