SPOJ Problem Set (classical)1167. Move To InvertProblem code: MINCOUNT |
将左边的三角形变成右边这样至少需要挪几枚硬币?
For h=4 at least 3 coins must be moved to invert it.
Input
In the first line N will be given and then N lines follow with each line having a integer which is the height of triangle in that test case.00≤h<1010;
Output
For each test case output in a seperate line the minimum number of moves required to invert the triangle. Output fits in long long data type
Example
Inputt: 1 3 Output: 2
答案是n(n+1) div 6
这是纯粹的打表找规律题……
注意Comments中对%lli的注解(等待C++有识之士解释……)
#include<cstdio>
#include<cstring>
using namespace std;
unsigned long long n;
int main()
{
scanf("%lli",&n);
while (scanf("%lli",&n)!=EOF) printf("%lli\n",n*(n+1)/6);
return 0;
}