这道题应该是比较裸的一道题目了。
最开始做的时候完全想不到用什么gcd之类的东西。。。
然后直接模拟旋转和翻转的过程求置换群去了。
虽然结果是对的,不过是n2的算法,还好题目的数据很小。
先进的算法可以看http://blog.csdn.net/shiren_Bod/article/details/5664934/
/*
ID: sdj22251
PROG: subset
LANG: C++
*/
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#define MAXN 1111111
#define MAXM 104444
#define INF 100000000
#define eps 1e-7
#define L(X) X<<1
#define R(X) X<<1|1
using namespace std;
int a[33][33], b[33];
long long as[33][33];
int v[33];
int n, k;
long long sum;
void get()
{for(int j = 1; j <= n; j++){memset(v, 0, sizeof(v));int cnt = 0;for(int i = 1; i <= n; i++){int t = a[j][i];if(!v[t]) cnt++;else continue;while(t != i){t = a[j][t];v[t] = 1;}}b[j] = cnt;}
}
void init()
{for(int i = 0; i < n; i++)for(int j = 1; j <= n; j++)a[i + 1][j] = (i + j - 1) % n + 1;get();for(int q = 1; q <= n; q++){sum += (long long )pow(k, b[q]);}for(int i = 0; i < n; i++)for(int j = 1; j <= n / 2; j++)swap(a[i + 1][j], a[i + 1][n - j + 1]);get();for(int q = 1; q <= n; q++){sum += (long long )pow(k, b[q]);}
}int main()
{k = 3;while(scanf("%d", &n) != EOF){if(n == -1) break;if(n == 0) {puts("0"); continue;}sum = 0;init();sum /= 2 * n;printf("%I64d\n", sum);}return 0;
}