Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4786)
- #pragma warning(disable:4996)
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/trie_policy.hpp>
- #define pii pair<int,int>
- #define pll pair<long long ,long long>
- #define pli pair<long long , int>
- #define pil pair<int ,long long>
- #define pi acos(-1)
- #define pb push_back
- #define mkp make_pair
- #define all(a) a.begin(), a.end()
- #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #define ll long long
- #define MAX 300005
- #define INF 0x3f3f3f3f
- template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
- template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);} // M is prime}
- using namespace std;
- using namespace __gnu_pbds;
- typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
- ll power(ll x, ll y, ll p)
- {
- ll res = 1LL; // Initialize result
- x = x % p; // Update x if it is more than or
- // equal to p
- while (y > 0)
- {
- // If y is odd, multiply x with result
- if (y & 1LL)
- res = (res*x) % p;
- // y must be even now
- y = y>>1LL; // y = y/2
- x = (x*x) % p;
- }
- return res;
- }
- // This function is called for all k trials. It returns
- // false if n is composite and returns false if n is
- // probably prime.
- // d is an odd number such that d*2<sup>r</sup> = n-1
- // for some r >= 1
- bool miillerTest(ll d, ll n)
- {
- // Pick a random number in [2..n-2]
- // Corner cases make sure that n > 4
- ll a = 2 + rand() % (n - 4);
- // Compute a^d % n
- ll x = power(a, d, n);
- if (x == 1LL || x == n-1LL)
- return true;
- // Keep squaring x while one of the following doesn't
- // happen
- // (i) d does not reach n-1
- // (ii) (x^2) % n is not 1
- // (iii) (x^2) % n is not n-1
- while (d != n-1LL)
- {
- x = (x * x) % n;
- d *= 2LL;
- if (x == 1LL) return false;
- if (x == n-1LL) return true;
- }
- // Return composite
- return false;
- }
- // It returns false if n is composite and returns true if n
- // is probably prime. k is an input parameter that determines
- // accuracy level. Higher value of k indicates more accuracy.
- bool isPrime(ll n, ll k)
- {
- // Corner cases
- if (n <= 1LL || n == 4LL) return false;
- if (n <= 3LL) return true;
- // Find r such that n = 2^d * r + 1 for some r >= 1
- int d = n - 1LL;
- while (d % 2LL == 0)
- d /= 2LL;
- // Iterate given nber of 'k' times
- for (ll i = 0LL; i < k; i++)
- if (!miillerTest(d, n))
- return false;
- return true;
- }
- set<int>primes;
- vector<int>prime;
- bitset<100000>bs;
- void sieve (int n){
- bs.set ();
- //prime.pb(2);
- for (int i = 2; i <= n; i++){
- if (bs[i])prime.pb(i);
- for (int j = 0; j<prime.size() && i*prime[j]<=n; j++){
- bs[i*prime[j]] = 0;
- if(i%prime[j]==0)break;
- }
- }
- }
- int main(){
- IOS
- //freopen("output.txt","w",stdout);
- int t;
- cin>>t;
- sieve(1000);
- map<ll,int>mp;
- for(auto it=prime.begin();it!=prime.end();it++){
- mp[(*it)]++;
- }
- for(int tt=0;tt<t;tt++){
- ll n;
- cin>>n;
- if(n<=11){
- cout<<"Case "<<tt+1<<": IMPOSSIBLE\n";
- continue;
- }
- ll ans;
- if(n<1000){
- ans=2LL;
- }
- else{
- for(ll i=n-10LL;;i--){
- if(isPrime(i,4LL)){
- ans = i;
- break;
- }
- }
- }
- vector<ll>vec;
- vec.pb(ans);
- ll now = n-ans;
- if(now&1LL){
- now-=7;
- vec.pb(2LL);
- vec.pb(2LL);
- vec.pb(3LL);
- }
- else{
- now-=6;
- vec.pb(2LL);
- vec.pb(2LL);
- vec.pb(2LL);
- }
- for(auto it =prime.begin();it!=prime.end();it++){
- if(mp[now-(*it)]>0){
- vec.pb((*it));
- vec.pb(now-(*it));
- sort(vec.begin(),vec.end());
- cout<<"Case "<<tt+1<<": ";
- for(auto it2 = vec.begin();it2!=vec.end();it2++){
- cout<<(*it2)<<" ";
- }
- break;
- }
- }
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement