#include<iostream>
#include<iomanip>
using namespace std;
class magic
{
public:
void getdata(int st,int f,int s)
{
step=st;
first=f;
sum=s;
}
void setfirstmagic()
{
int i,j;
for (i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
m[i][j]=first;
first+=step;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
cout<<setw(4)<<m[i][j];
}
cout<<endl;
}
}
void generatemagic()
{
int i,j;
for(i=0,j=0;i<4,j<4;i++,j++)
{
m[i][j]=sum-m[i][j];
}
for(i=0,j=3;i<4,j>=0;i++,j--)
{
m[i][j]=sum-m[i][j];
}
}
void printmagic()
{
cout<<endl;
cout<<"4*4魔方:"<<endl;
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
cout<<setw(4)<<m[i][j];
}
cout<<endl;
}
}
private:
int m[4][4];
int step;
int first;
int sum;
};
int main()
{
magic m1;
m1.getdata(2,1,32);
m1.setfirstmagic();
m1.generatemagic();
m1.printmagic();
return 0;
}