数学规律题
通过观察可以得出想要堆成i层高的塔至少需要卡牌数量为i*(3*i+1)/2,要求卡牌不能剩余,多余的卡牌如果是3 的倍数就可以摆在最下面,所以只需要遍历所能摆成最高的塔之间的所有层数即可
#include <iostream>//数据输入输出流
#include <string.h>//字符串操作函数
#include <stdio.h>//C的输入输出
#include <stdlib.h>//定义杂项函数及内存分配函数
#include <math.h>//C中的数学函数
#include <cstring>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor容器
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如:bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数(代替运算符)
//#include <iomanip.h>//参数化输入/输出
#include <limits.h>//定义各种数据类型最值常量
//#include <strstrea.h>//基于数组的输入/输出
//#include <fstream.h>//文件输入/输出
#define ll long long
using namespace std;
ll n;
ll cal ( ll i )
{
return i * ( 3 * i + 1 ) / 2;
}
int main()
{
cin >> n;
ll num=0;
for ( ll i = 1; cal ( i ) <= n; i++ )
{
if ( ( n - cal ( i ) ) % 3 == 0 )
{
num++;
}
}
cout<<num<<endl;
return 0;
}