Given expression [X/2] + Y + x * y, where X and Y are positive integers. The brackets indicate the following integers, for example, [3/2] = 1, [5/2] = 2. Some positive integers can be expressed using the above expression, for example, positive integer 2. When x = y = 1 is obtained, 2 can be expressed (explained below: When x = y = 1, [X/2] + Y + x * Y = [1/2] + 1 + 1*1 =
0 + 1 + 1 = 2); some numbers can be expressed in multiple ways. For example, 13 can be expressed by X = 2 y = 4 and x = 3 Y = 3; some numbers cannot be expressed using this expression, such as 3. The Nth number starting from 1 cannot be expressed by this expression. We call it an. For example, a1 = 1 A2 = 3. Given N, evaluate. Input: N value 1 <= n <= 40 output: An % 1000000007 result (because the result is large, output an % 1000000007 result ). Function header C/C ++: int givean (int n); Java: public class main
{Public static int givean (int n ){}}
#include <iostream>#include <vector>using namespace std;class Node{ public: Node(int a, int b) { y = b; value = (a>>1) + b + a*b; } void increase(int x) { y++; value = (x>>1) + y + x*y; } int y; long long int value;};int givean(int n){ vector<Node> buf; buf.push_back(Node(0,0)); buf.push_back(Node(1,2)); buf.push_back(Node(2,1)); long long int preNum = 2; long long int curNum = 2; int preCount = 1; int curCount = 1; int result = 1; while (curCount < n) { int x = 1; int y = buf[1].y; int curNum = buf[1].value; int size = buf.size(); int i = 2; for (; i < size; i++) { if ((buf[i].value) == preNum) { buf[i].increase(i); } if ((buf[i].value) < curNum) { x = i; y = buf[i].y; curNum = buf[i].value; } } if (i == (size-1)) { buf.push_back(Node(size,1)); } buf[x].increase(x); if (curNum != preNum+1) { curCount = preCount + (curNum-preNum-1); if (curCount >= n) { result = preNum + (n-preCount); break; } else { preCount = curCount; } } preNum = curNum; } return result;}int main(){ for (int i = 1; i <= 40; i++) { cout << givean(i) << endl; } return 0;}