提交时间:2024-10-30 15:27:36
运行 ID: 33926
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define int long long int n,k; inline int gcd(int a,int b){ return b==0?a:gcd(b,a%b); } signed main(){ ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); // freopen("tree.in","r",stdin); // freopen("tree.out","w",stdout); cin>>n>>k; // cout<<n<<" "<<k<<endl;//////////////////// if(n%2==0){ cout<<-1<<endl; return 0; } else if(gcd(n,k)==1){ cout<<n/2<<endl; int now=0; for(int i=1;i<=n/2;i++){ cout<<now<<" "<<(now+1)%n<<endl; now=(now+2*k)%n; } } else{ cout<<n/2<<endl; int t=gcd(n,k); k/=t; int c=n/t; int now=0; for(int i=1;i<=c/2;i++){ int x=now; for(int j=0;j<t-1;j++) cout<<x+j<<" "<<x+j+1<<endl; cout<<x<<" "<<x+2*t-1<<endl; now=(now+2*k*t)%n; } // cerr<<now<<" "<<k<<" "<<c<<endl; for(int i=1;i<=t/2;i++){ int x=now,y=now+1; // cerr<<x<<" "<<y<<endl; cout<<x<<" "<<(y-k*t+n)%n<<endl; now+=2; } } cout.flush(); return 0; }