#include <iostream>
#include <vector>
#include <cstdint>
#include <cmath>
#include <iomanip>
#include <tuple>
typedef std::vector<std::vector<std::uint64_t>> DType;
typedef std::tuple<DType, std::uint64_t, std::uint64_t, std::uint64_t> RType;
DType MakeVector(std::size_t N){
DType R(N);
for (auto& o : R)o.resize(N);
return R;
}
bool Show(RType& R){
std::cout << "Result:Call = " << std::get<1>(R) << " Accept = " << std::get<2>(R)<<"*"<<std::get<2>(R) << " Moded@ " << std::get<3>(R) << "Count!!" << std::endl;
for (auto& oo : std::get<0>(R)){
for (auto& o : oo){
std::cout << std::setw(3) << std::left << o << ' ';
}
std::cout << std::endl;
}
return true;
}
bool RollingThunder(DType& D, std::uint64_t N){
std::int64_t X = 0, Y = 0;
std::int64_t i = 1;
std::int64_t L = 0, R = 0, U = 0, B = 0;
while (i <= N){
for (X = L; X < (D[Y].size() - R); X++, i++) D[Y][X] = i;
U++;
X=(D[Y].size() - R)-1;
for (Y = U; Y < (D.size() - B); Y++, i++)D[Y][X] = i;
R++;
Y=(D.size() - B)-1;
for (X=(D[Y].size() - R)-1; X >=L; X--, i++) D[Y][X] = i;
B++;
X=L;
for (Y=(D.size() - B)-1; Y >=U; Y--, i++) D[Y][X] = i;
L++;
Y=U;
//Show(D);
}
return true;
}
RType MakeHoge(std::uint64_t N){
std::uint64_t X = std::sqrt(N);
if (X % 2 == 0) X--;
std::uint64_t Y = N - (X*X);
DType D = MakeVector(X);
RollingThunder(D, X*X);
return std::make_tuple(D,N,X,Y);
}
int main(){
RType R;
for (int i = 1; i < 16; i += 2){
R = MakeHoge(i*i);
Show(R);
}
R = MakeHoge(25*25+6);
Show(R);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPHR1cGxlPgoKdHlwZWRlZiBzdGQ6OnZlY3Rvcjxzd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