Language: C++

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define reg register
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a )
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a )
#define debug(x) cerr<<#x<<" = "<<x<<endl;

template<class T>inline bool Max(T &a,T b) {
	return a<b?a=b,1:0;
}
template<class T>inline bool Min(T &a,T b) {
	return a>b?a=b,1:0;
}

inline int Read(void) {
	int res=0,flag=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')flag=0;
	do res=(res<<1)+(res<<3)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return flag?res:-res;
}

const int N=8e8+5,M=1e6+5,mod=1e9+7;
const int dx[4]= {1,-1,0,0},dy[4]= {0,0,1,-1};

int n,k,m,A[N],B[N];

int main(void) {
	n=Read(),k=Read();
	if(k>(n-1)*(n-2)/2)return puts("-1");
	int z;
	for(reg int i=1; i<=n; i++) {
		if(i*(i-1)/2<=k&&(i+1)*i/2>k) {
			z=i;
			break;
		}
	}
	k=k-(z-1)*z/2;
	rep(i,2,z+1)m++,A[m]=i,B[m]=1;
	rep(i,z+2,z+1+k)m++,A[m]=i,B[m]=i-z;
	rep(i,z+2+k,n)ret(j,1,i)m++,A[m]=i,B[m]=j;
	printf("%d\n",m);
	rep(i,1,m)printf("%d %d\n",A[i],B[i]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |         for(reg int i=1; i<=n; i++) {
      |                     ^
a.cc:44:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |         rep(i,2,z+1)m++,A[m]=i,B[m]=1;
      |             ^
a.cc:7:32: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                ^
a.cc:44:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |         rep(i,2,z+1)m++,A[m]=i,B[m]=1;
      |             ^
a.cc:7:38: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                      ^
a.cc:45:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |         rep(i,z+2,z+1+k)m++,A[m]=i,B[m]=i-z;
      |             ^
a.cc:7:32: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                ^
a.cc:45:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |         rep(i,z+2,z+1+k)m++,A[m]=i,B[m]=i-z;
      |             ^
a.cc:7:38: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                      ^
a.cc:46:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         rep(i,z+2+k,n)ret(j,1,i)m++,A[m]=i,B[m]=j;
      |             ^
a.cc:7:32: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                ^
a.cc:46:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         rep(i,z+2+k,n)ret(j,1,i)m++,A[m]=i,B[m]=j;
      |             ^
a.cc:7:38: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                      ^
a.cc:46:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         rep(i,z+2+k,n)ret(j,1,i)m++,A[m]=i,B[m]=j;
      |                           ^
a.cc:8:32: note: in definition of macro 'ret'
    8 | #define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a )
      |                                ^
a.cc:46:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         rep(i,z+2+k,n)ret(j,1,i)m++,A[m]=i,B[m]=j;
      |                           ^
a.cc:8:38: note: in definition of macro 'ret'
    8 | #define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a )
      |                                      ^
a.cc:48:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         rep(i,1,m)printf("%d %d\n",A[i],B[i]);
      |             ^
a.cc:7:32: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                ^
a.cc:48:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         rep(i,1,m)printf("%d %d\n",A[i],B[i]);
      |             ^
a.cc:7:38: note: in definition of macro 'rep'
    7 | #define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
      |                                      ^
/tmp/cchMmzyp.o: in function `main':
a.cc:(.text+0x121): relocation truncated to fit: R_X86_64_PC32 against symbol `B' defined in .bss section in /tmp/cchMmzyp.o
a.cc:(.text+0x18e): relocation truncated to fit: R_X86_64_PC32 against symbol `B' defined in .bss section in /tmp/cchMmzyp.o
a.cc:(.text+0x1fc): relocation truncated to fit: R_X86_64_PC32 against symbol `B' defined in .bss section in /tmp/cchMmzyp.o
a.cc:(.text+0x24d): relocation truncated to fit: R_X86_64_PC32 against symbol `B' defined in .bss section in /tmp/cchMmzyp.o
collect2: error: ld returned 1 exit status