哎。。。直接往上枚举就行了。
不过我还是加了点小的优化。。
但是很纯暴力相比感觉没优化多少。。都是O(n ^ 2)的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <stack>
#include <cmath>
#define eps 1e-6
#define INF 1000000007
#define PI acos(-1.0)
using namespace std;
bool ok(int x)
{x = x * 12 + 1;int m = (int)sqrt(x * 1.0);if(m * m == x && (m + 1) % 6 == 0) return 1;return 0;
}
bool gao(int x)
{int m = (int)sqrt(x * 1.0);for(int i = 2; i <= m; i++){if(x % i == 0){int t = x / i;if((t + 1) % 3 != 0) continue;if(t - 3 * i + 1 < 6) break;int k1 = (t + 1) / 3;int k2 = i;if((k1 + k2) % 2 == 1 || k1 <= k2) continue;int a = (k1 + k2) / 2;int b = (k1 - k2) / 2;if(ok(3 * (a * a + b * b) - a - b)) return 1;}}return 0;
}
int main()
{for(int i = 5; ; i++){if(gao(i * (3 * i - 1))){cout << i * (3 * i - 1) / 2 << endl;break;}}return 0;
}