题意:
对于式子
a1(x1)3+a2(x2)3+a3(x3)3+a4(x4)3+a5(x5)3=0
a1~a5都已经给出,x1~x5都是从[-50,50]且不包含0.
思路:
转换一下式子为
a1(x1)3+a2(x2)3=−(a3(x3)3+a4(x4)3+a5(x5)3)
则枚举x1,x2,将所得的结果存在map里(记录出现次数)。再枚举x3,x4,x5,查询map,将次数累加即可。
code:
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
int a[6];
map <int, int> mp;
map <int, int>::iterator it;
inline int mpow(int v) {
return v*v*v;
}
void solve() {
mp.clear();
int tmp;
for(int i = -50;i <= 50; i++) {
for(int j = -50;j <= 50; j++) {
if(i == 0 ||j == 0) continue;
tmp = -(a[0]*mpow(i)+a[1]*mpow(j));
if((it=mp.find(tmp)) != mp.end())
(it->second)++;
else mp[tmp] = 1;
}
}
int res = 0;
for(int i = -50;i <= 50; i++) {
if(i == 0) continue;
for(int j = -50;j <= 50; j++) {
if(j == 0) continue;
for(int z = -50;z <= 50; z++) {
if(z == 0) continue;
tmp = a[2]*mpow(i)+a[3]*mpow(j)+a[4]*mpow(z);
if((it=mp.find(tmp)) != mp.end())
res += it->second;
}
}
}
printf("%d\n", res);
}
int main() {
while(scanf("%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &a[4]) != EOF) {
solve();
}
return 0;
}