Description
考虑方程a1a_1a1x13 x_1^3x13 +a2a_2a2x23 x_2^3x23 +a3a_3a3 x33x_3 ^3x33=000,系数是在[-50,50]区间的整数,xi∈[−50,50]x_i∈[-50,50]xi∈[−50,50],xi!=0x_i!=0xi!=0,i∈1,2,3,4,5i∈{1,2,3,4,5}i∈1,2,3,4,5,求满足方程的解的数量。
Format
Input
唯一的输入行包含5个系数a1、a2、a3、a4、a5a_1 、a_2 、a_3 、a_4 、a_5a1、a2、a3、a4、a5 ,以空格分隔。.
Output
单行输出满足方程的解的数量。
Samples
##输入数据 1
37 29 41 43 47
输出数据 1
654
#include <iostream>
#include <cstring>
using namespace std;
#define N 31250000
short hashs[N];
short hashsfu[N];
int main(){
int a1,a2,a3,a4,a5;
long the_end;
cin >> a1 >> a2 >> a3 >> a4 >> a5;
memset(hashs,0,sizeof(hashs));
for (int i = -50; i <= 50; i++)
{
for (int j = -50; j <= 50; j++)
{
for (int z = -50; z <= 50; z++)
{
if(i == 0 || j==0 || z == 0) continue;
the_end = i*i*i*a1 + j*j*j *a2 + z*z*z*
a3;
if(the_end < 0 ){
hashsfu[the_end*-1]++;
}else{
hashs[the_end]++;
}
}
}
}
long ans = 0;
for (int i = -50; i <= 50; i++){
for (int j = -50; j <= 50; j++){
if(i==0 || j == 0) continue;
the_end = -1*(i*i*i*a4 + j*j*j*a5);
if(the_end < 0 ){
ans+=hashsfu[the_end*-1];
}else{
ans+=hashs[the_end];
}
}
}
cout << ans ;
}