View Code of Problem 3698

#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;
//思想:先用玻璃珠一堆一堆减,直到玻璃珠比这一堆要小,定位堆,再用剩下的玻璃珠一层一层减,直到玻璃珠比这一层的数量少,定位层,剩下的玻璃珠就是第几列 
int main(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		ll num;
		cin>>num;
		ll duinum=1;
		ll dui=1;
		while(num>duinum){//剩余玻璃珠大于这儿一堆的数量 
			num-=duinum;//玻璃珠减去这一堆
			dui++;//堆号++
			duinum+= dui;//下一堆的玻璃珠等于现在的加堆号 
		}
		ll cengnum=1;
		ll ceng=1;	
		while(num>cengnum){ 
			num-=cengnum;
			ceng++;//层号++
			cengnum=ceng;//下一层的玻璃珠? 
		} 
		cout<<dui<<" "<<ceng<<" "<<num<<endl; 
				
	}
}

Double click to view unformatted code.


Back to problem 3698