Advertisement
Plabon_dutta

D1 Prb D

Oct 13th, 2022 (edited)
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include<cmath>
  3. #include<vector>
  4. #include<string>
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8.  
  9. typedef long long int ll;
  10.  
  11. const ll mod = 1e9+7;
  12.  
  13. #define pi atan(1)*4
  14. #define sc scanf
  15. #define pf printf
  16. #define fin for(ll i=0; i<n; i++)
  17. #define fiz for(ll i=n-1; i>=0; i--)
  18. #define fjm for(ll j=0; j<m; j++)
  19. #define fr(i,a,n) for(ll i=a; i<n; i++)
  20. #define pb push_back
  21. #define pb2(x,y) push_back(make_pair(x,y))
  22. #define INF 1e18
  23. #define nl '\n'
  24. #define sz(a) a.size()
  25. #define readfirst() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  26. #define make(a,n) memset(a, n, sizeof(a))
  27. #define all(x) x.begin(),x.end()
  28. #define fixpre(x) fixed << setprecision(x)
  29.  
  30.  
  31. void OJ() {
  32.     #ifndef ONLINE_JUDGE
  33.     freopen("input.txt","r", stdin);
  34.     freopen("output.txt","w", stdout);
  35.     #endif
  36. }
  37.  
  38. ll gcd(ll p, ll q) {
  39.     return q==0?p:gcd(q,p%q);
  40. }
  41.  
  42. bool isPowerOfTwo(ll n) {
  43.    if(n==0)
  44.    return false;
  45.    return (ceil(log2(n)) == floor(log2(n)));
  46. }
  47.  
  48. ll power(ll a, ll n) {
  49.     if(n==1) return a%mod;
  50.     ll x=power(a,n/2);
  51.     if(n%2==0) return (x*x)%mod;
  52.     else return (x*x)%mod*a%mod;
  53. }
  54.  
  55. ll digitSum(ll n) {
  56.     ll s=0;
  57.     while(n>0) {
  58.         s+=n%10;
  59.         n/=10;
  60.     }
  61.     return s;
  62. }
  63.  
  64. ll digitMult(ll n) {
  65.     ll s=1;
  66.     while(n>0) {
  67.         if(n%10) s*=(n%10);
  68.         n/=10;
  69.     }
  70.     return s;
  71. }
  72.  
  73. ll NoofDigit(ll n) {
  74.     ll s=0;
  75.     while(n>0) {
  76.         s++;
  77.         n/=10;
  78.     }
  79.     return s;
  80. }
  81.  
  82. ll fact(ll n){
  83.     return tgamma(n + 1);
  84. }
  85.  
  86. bool isPrime(ll n) {
  87.     if (n <= 1) return false;
  88.     for (ll i=2; i*i<=n; i++) {
  89.         if (n % i == 0) return false;
  90.     }
  91.     return true;
  92. }
  93.  
  94. int main() {
  95.     auto st = clock();
  96.     readfirst();
  97.     OJ();
  98.    
  99.     ll testcase=1, count=1;
  100.     // cin >> testcase;
  101.     // cin.ignore();
  102.     while(testcase--) {
  103.         // cout << "Case " << count++ << ": ";
  104.         ll n;
  105.         cin >> n;
  106.         if(n<4) cout << -1 << nl;
  107.         else if(n%2==0) {
  108.             cout << n/2 << nl;
  109.             vector<ll> v;
  110.             ll c=1;
  111.             fin {
  112.                 v.pb(c);
  113.                 c+=2;
  114.             }
  115.             ll l=0, r=n-1;
  116.             for(ll i=0; i<n/2; i++) {
  117.                 cout << 2 << ' ';
  118.                 cout << v[l] << ' ' << v[r] << nl;
  119.                 c++;
  120.                 l++;
  121.                 r--;
  122.             }
  123.         }
  124.         else {
  125.             if(isPrime(n)) cout << -1 << nl;
  126.             else {
  127.                 vector<ll> v;
  128.                 ll num, num2;
  129.                 bool flag=false;
  130.                 bool flag2=false;
  131.                 for(ll i=2; i<=sqrt(n); i++) {
  132.                     if(n%i==0) {
  133.                         if(n/i!=i) {
  134.                             v.pb(i);
  135.                             v.pb(n/i);
  136.                         }
  137.                         else {
  138.                             v.pb(i);
  139.                             flag=true;
  140.                             num=i;
  141.                         }
  142.                         if(n/i>i) {
  143.                             flag2=true;
  144.                             num2=i;
  145.                         }
  146.                     }
  147.                 }
  148.                 vector<ll> vv;
  149.                 ll c=1;
  150.                 fin {
  151.                     vv.pb(c);
  152.                     c+=2;
  153.                 }
  154.                 if(flag) {
  155.                     cout << num << nl;
  156.                     c=0;
  157.                     ll c2=0;
  158.                     vector<ll> a[num];
  159.                     ll x=num;
  160.                     for(ll i=0; i<num; i++) {
  161.                         c+=c2;
  162.                         for(ll j=0; j<x; j++) {
  163.                             a[i].pb(vv[c]);
  164.                             c++;
  165.                         }
  166.                         ll z=i*num;
  167.                         for(ll j=x; j<num; j++) {
  168.                             a[i].pb(vv[z]);
  169.                             z++;
  170.                         }
  171.                         x--;
  172.                         c2++;
  173.                     }
  174.                     for(ll i=0; i<num; i++) {
  175.                         cout << num << ' ';
  176.                         for(ll j=0; j<num; j++) {
  177.                             cout << a[j][i] << ' ';
  178.                         }
  179.                         cout << nl;
  180.                     }
  181.                 }
  182.                 else if(flag2) {
  183.                    
  184.                 }
  185.                 else cout << -1 << nl;
  186.             }
  187.         }
  188.     }
  189.    
  190.    
  191.     // while(cin >> n) {
  192.     //     // if(n==0) break;
  193.        
  194.     // }
  195.    
  196.     cerr << 1.0 * (clock()-st) / CLOCKS_PER_SEC << " Seconds" << nl;
  197.     return 0;
  198. }
  199.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement