2014
03-01

The Mystery of Triangle

There’re some unresolved problems of triangle so far. For example, whether there’s a three middle integer Helen triangle? It is unable to prove its existence until now; they have not found such a triangle. But I’ m sure you can solve this problem. Now, there is an equilateral triangle（等边三角形）,each edge is divided into two equal parts. Such as the picture

and if each edge is divided into three equal parts,
the triangle becomes

,now you task is to count the number of triangles, diamonds（菱形）, and parallelograms（平行四边形）.

Each line will contain a integer n (1 < n < 2^31 – 1). It means each edge of triangle is divided into n equal parts. Process to the end of input.

Each line will contain a integer n (1 < n < 2^31 – 1). It means each edge of triangle is divided into n equal parts. Process to the end of input.

2
3

Triangle: 5
Diamond: 3
Parallelogram: 3
Triangle: 13
Diamond: 9
Parallelogram: 15

/*
* hdu3083/win.cpp
* Created on: 2012-7-15
* Author    : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;

const int MOD = 20091226;
typedef long long LL;

inline int getS(LL n) {
LL mod = MOD * 6;
LL ret = (n % mod) * ((n + 1) % mod);
ret %= mod;
ret *= (n + 2) % mod;
ret %= mod;
ret /= 6;
return (int)ret;
}

inline int getX(LL n) {
if(n <= 1) {
return 0;
}
int mod = MOD * 24;
LL ret = (n + 1) % mod;
if(n % 2 == 1) {
ret = (((2 * ret  - 3) * ret) % mod - 2) * ret;
}else {
ret = (n % mod) * ((n + 2) % mod);
ret %= mod;
ret *= (2 * n - 1) % mod;
}
ret %= mod;
ret /= 24;
return ret;
}

inline int getP(LL n) {
if(n < 1) {
return 0;
}
int mod = MOD * 8;
LL ret = n % mod;
ret = ((((ret * (ret + 1))% mod) * (ret + 2))% mod) * (ret + 3);
ret %= mod;
ret /= 8;
return ret;
}

int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int n;
LL t, d, p, s, x;
while(scanf("%d", &n) == 1) {
s = getS(n);
x = getX(n);
t = s + x;
d = 3 * x;
p = getP(n - 1);
printf("Triangle: %d\n", t % MOD);
printf("Diamond: %d\n", d % MOD);
printf("Parallelogram: %d\n", p % MOD);
}
return 0;
}

1. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks

2. 我还有个问题想请教一下，就是感觉对于新手来说，递归理解起来有些困难，不知有没有什么好的方法或者什么好的建议？