Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include<cmath>
- #include<vector>
- #include<string>
- #include<algorithm>
- using namespace std;
- typedef long long int ll;
- const ll mod = 1e9+7;
- #define pi atan(1)*4
- #define sc scanf
- #define pf printf
- #define fin for(ll i=0; i<n; i++)
- #define fiz for(ll i=n-1; i>=0; i--)
- #define fjm for(ll j=0; j<m; j++)
- #define fr(i,a,n) for(ll i=a; i<n; i++)
- #define pb push_back
- #define pb2(x,y) push_back(make_pair(x,y))
- #define INF 1e18
- #define nl '\n'
- #define sz(a) a.size()
- #define readfirst() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
- #define make(a,n) memset(a, n, sizeof(a))
- #define all(x) x.begin(),x.end()
- #define fixpre(x) fixed << setprecision(x)
- void OJ() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","r", stdin);
- freopen("output.txt","w", stdout);
- #endif
- }
- ll gcd(ll p, ll q) {
- return q==0?p:gcd(q,p%q);
- }
- bool isPowerOfTwo(ll n) {
- if(n==0)
- return false;
- return (ceil(log2(n)) == floor(log2(n)));
- }
- ll power(ll a, ll n) {
- if(n==1) return a%mod;
- ll x=power(a,n/2);
- if(n%2==0) return (x*x)%mod;
- else return (x*x)%mod*a%mod;
- }
- ll digitSum(ll n) {
- ll s=0;
- while(n>0) {
- s+=n%10;
- n/=10;
- }
- return s;
- }
- ll digitMult(ll n) {
- ll s=1;
- while(n>0) {
- if(n%10) s*=(n%10);
- n/=10;
- }
- return s;
- }
- ll NoofDigit(ll n) {
- ll s=0;
- while(n>0) {
- s++;
- n/=10;
- }
- return s;
- }
- ll fact(ll n){
- return tgamma(n + 1);
- }
- bool isPrime(ll n) {
- if (n <= 1) return false;
- for (ll i=2; i*i<=n; i++) {
- if (n % i == 0) return false;
- }
- return true;
- }
- int main() {
- auto st = clock();
- readfirst();
- OJ();
- ll testcase=1, count=1;
- // cin >> testcase;
- // cin.ignore();
- while(testcase--) {
- // cout << "Case " << count++ << ": ";
- ll n;
- cin >> n;
- if(n<4) cout << -1 << nl;
- else if(n%2==0) {
- cout << n/2 << nl;
- vector<ll> v;
- ll c=1;
- fin {
- v.pb(c);
- c+=2;
- }
- ll l=0, r=n-1;
- for(ll i=0; i<n/2; i++) {
- cout << 2 << ' ';
- cout << v[l] << ' ' << v[r] << nl;
- c++;
- l++;
- r--;
- }
- }
- else {
- if(isPrime(n)) cout << -1 << nl;
- else {
- vector<ll> v;
- ll num, num2;
- bool flag=false;
- bool flag2=false;
- for(ll i=2; i<=sqrt(n); i++) {
- if(n%i==0) {
- if(n/i!=i) {
- v.pb(i);
- v.pb(n/i);
- }
- else {
- v.pb(i);
- flag=true;
- num=i;
- }
- if(n/i>i) {
- flag2=true;
- num2=i;
- }
- }
- }
- vector<ll> vv;
- ll c=1;
- fin {
- vv.pb(c);
- c+=2;
- }
- if(flag) {
- cout << num << nl;
- c=0;
- ll c2=0;
- vector<ll> a[num];
- ll x=num;
- for(ll i=0; i<num; i++) {
- c+=c2;
- for(ll j=0; j<x; j++) {
- a[i].pb(vv[c]);
- c++;
- }
- ll z=i*num;
- for(ll j=x; j<num; j++) {
- a[i].pb(vv[z]);
- z++;
- }
- x--;
- c2++;
- }
- for(ll i=0; i<num; i++) {
- cout << num << ' ';
- for(ll j=0; j<num; j++) {
- cout << a[j][i] << ' ';
- }
- cout << nl;
- }
- }
- else if(flag2) {
- }
- else cout << -1 << nl;
- }
- }
- }
- // while(cin >> n) {
- // // if(n==0) break;
- // }
- cerr << 1.0 * (clock()-st) / CLOCKS_PER_SEC << " Seconds" << nl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement