Submission #227501

# Submission time Handle Problem Language Result Execution time Memory
227501 2020-04-27T14:59:57 Z kshitij_sodani Lutrija (COCI19_lutrija) C++17
70 / 70
356 ms 504 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back

#define endl "\n"
llo ip(llo aa){
	if(aa==1){
		return 0; 
	}
	llo j=2;
	while(j*j<=aa){
		if(aa%j==0){
			return 0;
		}
		j+=1;
	}
	return 1;
}
vector<llo> solve(llo a,llo b){
	if(a==b){
		return {a};
	}
	if(a==2){
		if(ip(b-a)){
			return {a,b};
		}
		if(ip(b+2-a) and ip(b+2)){
			return {a,b+2,b};
		}
		if(b-2>a){
			if(ip(b-2-a) and ip(b-2)){
				return {a,b-2,b};
			}
		}
		return {-1};
	}
	else{
		llo st=1;
		if(b-a<=4){
			for(llo i=a;i<=b;i+=2){
				if(ip(i)==0){
					st=0;
				}
			}
		}
		else{
			st=0;
		}
		if(st){
			vector<llo> ans2;
			for(llo i=a;i<=b;i+=2){
				ans2.pb(i);
			}
			return ans2;
		}
		vector<llo> x=solve(2,a);
		vector<llo> y=solve(2,b);
		if(x[0]==-1 or y[0]==-1){
			return {-1};
		}
		reverse(x.begin(),x.end());
		vector<llo> ans3;
		for(auto j:x){
			if(j>2){
				ans3.pb(j);
			}
		}
		for(auto j:y){
			
				ans3.pb(j);
			
		}
		return ans3;

	}
	

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	llo a,b;
	cin>>a>>b;
	vector<llo> ans=solve(min(a,b),max(b,a));
	if(ans[0]==-1){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans.size()<<endl;
	if(a>b){
		reverse(ans.begin(),ans.end());
	}
	for(auto j:ans){
		cout<<j<<" ";
	}
	cout<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 480 KB Output is correct
2 Correct 238 ms 504 KB Output is correct
3 Correct 197 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 319 ms 504 KB Output is correct
2 Correct 210 ms 504 KB Output is correct
3 Correct 144 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 376 KB Output is correct
2 Correct 256 ms 424 KB Output is correct
3 Correct 132 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 376 KB Output is correct
2 Correct 182 ms 504 KB Output is correct
3 Correct 51 ms 388 KB Output is correct