2014
02-17

# F(N)

Giving the N, can you tell me the answer of F(N)?

Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed.

Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed.

1
2
3
0

1
7
20

/*
* hdu2802/win.cpp
* Created on: 2011-10-28
* 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 = 2009 * 4;

int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int n;
long long ans;
while (scanf("%d", &n) == 1 && n > 0) {
ans = (n + 1);
ans *= (n + 1);
ans %= MOD;
ans *= (2 * n - 1);
ans %= MOD;
if (n % 2 == 0) {
ans++;
}
ans %= MOD;
ans /= 4;
printf("%d\n", (int) ans);
}
return 0;
}

1. 5.1处，反了；“上一个操作符的优先级比操作符ch的优先级大，或栈是空的就入栈。”如代码所述，应为“上一个操作符的优先级比操作符ch的优先级小，或栈是空的就入栈。”