分成两部分,先打表 所有a1x1^3+a2x2^3可能出现的值。
再遍历所有a3x3^3+a4x4^3+a5x5^3可能取值。
用map会超时。哎。用数组。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <map>
using namespace std;
#define N 25000001
int a1,a2,a3,a4,a5;
short _map[N];
int count = 0;
void process(){
for(int x1=-50;x1<=50;++x1){
if(x1==0)
continue;
for(int x2=-50;x2<=50;++x2){
if(x2==0)
continue;
int sum = -a1*x1*x1*x1-a2*x2*x2*x2;
if(sum>=0)
++_map[sum];
else
++_map[sum+25000000];
}
}
for(int x3=-50;x3<=50;++x3){
if(x3==0)
continue;
for(int x4=-50;x4<=50;++x4){
if(x4==0)
continue;
for(int x5=-50;x5<=50;++x5){
if(x5==0)
continue;
int sum = a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
if(sum>0)
count += _map[sum];
else
count += _map[sum+25000000];
}
}
}
cout<<count<<endl;
}
int main(){
cin>>a1>>a2>>a3>>a4>>a5;
process();
system("pause");
return 0;
}