A lot of balls form a pyramid
Layer X has x * (x + 1)/2 balls.
Give you a second to represent the second ball at the first layer of the pyramid.
The number of rows in the layer at which it is located
Formula 1: x * (x + 1) * (x + 2)/6
Formula 2: x * (x + 1)/2
Formula 1 is the first n of formula 2 and
# Include <cstdio> # include <cstring> # include <cstdlib> # include <string> # include <iostream> # include <algorithm> # include <sstream> # include <cmath> using namespace STD; # include <queue> # include <stack> # include <vector> # include <deque> # include <set> # include <map> # include <time. h >;# define CLer (ARR, Val) memset (ARR, Val, sizeof (ARR) # define for (I, a, B) for (INT I =; I <= B; I ++) # define in freopen ("in.txt", "R", Stdin); # define out freopen ("out.txt", "W", stdout); typedef long ll; const int maxn = 10323; const int maxm = 201; const int INF = 0x3f3f3f; const int mod = 1000000007; ll getnum1 (LL num) {ll x = num; ll y = num + 1; ll z = num + 2; if (X % 2 = 0) x/= 2; else if (Y % 2 = 0) y/= 2; else if (Z % 2 = 0) z/= 2; If (X % 3 = 0) x/= 3; else if (Y % 3 = 0) y/= 3; else if (Z % 3 = 0) z/= 3; return x * y * z;} ll getnum2 (LL num) {return num * (Num + 1)/2;} int main () {# ifndef online_judge freopen ("in.txt", "r", stdin); # endif int t; ll N; scanf ("% d", & T); While (t --) {CIN> N; ll l = 0, r = 3810776; // R indicates the limit .. While (L <= r) // calculates the layer {ll mid = (L + r)> 1; // getnum1 (3810776) if (getnum1 (MID)> = N) r = mid-1; else l = Mid + 1;} ll ans1 = L; n-= getnum1 (L-1); L = 0, r = 3810776; while (L <= r) // find the nth row {ll mid = (L + r)> 1; if (getnum2 (MID)> = N) R = mid-1; else l = Mid + 1;} n-= getnum2 L-1); LL ans2 = L; printf ("% i64d % i64d % i64d \ n ", ans1, ans2, n );}}
[2] HDU 2446 shell pyramid