Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 8484 | Accepted: 4187 |
Description
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
The coefficients are given integers from the interval [-50,50].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.
Determine how many solutions satisfy the given equation.
Input
Output
Sample Input
37 29 41 43 47
Sample Output
654
Source
// 题意很明显 求解的个数
// hash保存一半结果 再去检测另一半
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define Y 18750003
using namespace std;
char hz[Y],hf[Y];
int main()
{
int a1,a2,a3,a4,a5;
int i,j,k,n,t;
while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)!=EOF)
{
for(i=0;i<Y;i++)
hz[i]=hf[i]=0;
for(i=-50;i<=50;i++)
if(i!=0)
{
for(j=-50;j<=50;j++)
if(j!=0)
{
for(k=-50;k<=50;k++)
if(k!=0)
{
t=a1*i*i*i+a2*j*j*j+a3*k*k*k;
if(t>=0)
hz[t]++;
else
hf[-t]++;
}
}
}
n=0;
for(i=-50;i<=50;i++)
if(i!=0)
{
for(j=-50;j<=50;j++)
if(j!=0)
{
t=a4*i*i*i+a5*j*j*j;
if(t>0)
n+=hf[t];
else
n+=hz[-t];
}
}
printf("%d\n",n);
}
return 0;
}