原题目:
题目大意:
解题思路:
这时候就可以去暴力搜索答案了
代码:
import math
maxn = 211345365
x= -1
p=1;
k=2
while(p<=30):
u=5*k*k+14*k+1;
j=int(math.sqrt(u));
if(u==j*j):
print(p,k);
p=p+1;
k=k+1
但是很遗憾,这个题,数据量要求有点大了,我Python跑了半个小时也只能跑到第21个
考虑进一步优化,转化成求二次方程解的问题:
此时该程序已经变得非常强大。
代码:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip> //cout输出精度控制需要,fixed、setpercison()
#include <time.h>
#include <map>
using namespace std;
#define ll long long
ll A[2000000], B[2000000], C[2000000],D[30000000],D1[30000000];
ll E[1000][1000];
ll R[100][50][50];
bool bA[10000000];
map <ll, bool> Map4;
ll ans1 = 0, ans2 = 0, flag;
struct Math{ //自用函数模板
const double Pi = acos(-1);
const double E = 2.718281828459;
struct STL{
}Stl;
struct Num_Theory {
/*struct Pythagorean_triangle {
ll a, b, c;
}Ptg_r[10000000];
ll Ptg_r_cnt=0;
void get_Ptg_r(ll tar) {
ll i, j, k,p,q;
ll x, y, z;
for (i = 1; i * i < tar; i++) {
if (i & 1)j = 2;
else j = 1;
for (; j < i; j+=2) {
x = 2 * i * j;
y = i * i - j * j;
z = i * i + j * j;
if (x + y + z > tar)break;
if (x > y) {
k = y;
y = x;
x = k;
}
if (y - x != 1)continue;
if (gcd(i, j) == 1) {
//