ACM模版

描述

题解

用归纳法证明该数列为 res[i] = res[i - 1] - res[i - 2],最后找到数列的封闭式即可,也就是通项公式,也可以多写几项,然后可以发现这是个循环,直接搞一下循环就 GG 了。

这个题不难,关键是你要会三角函数的相关推导……

代码

#include <iostream>

using namespace std;

const int res[] = {
  2, 1, -1, -2, -1, 1};

int main(int argc, const char * argv[])
{
    long long n;

    while (cin >> n)
    {
        cout << res[n % 6] << '\n';
    }

    return 0;
}