Description
Consider equations having the following form:
a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=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.
a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=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
The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
Output
The output will contain on the first line the number of the solutions for the given equation.
Sample Input
37 29 41 43 47
Sample Output
654
暴力+标记
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <ctime> 5 #include <iostream> 6 #include <algorithm> 7 #include <set> 8 #include <vector> 9 #include <sstream> 10 #include <queue> 11 #include <typeinfo> 12 #include <map> 13 #include <stack> 14 #define inf 0xfffff 15 typedef long long ll; 16 using namespace std; 17 #define MAXN 25000000 18 #define mod 10007 19 #define eps 1e-9 20 short hash[25000001]; 21 int main() 22 { 23 int a1,a2,a3,a4,a5; 24 while(scanf("%d %d %d %d %d",&a1,&a2,&a3,&a4,&a5)!=EOF) 25 { 26 int sum=0; 27 for(int i=-50; i<=50; i++) 28 for(int j=-50; j<=50; j++) 29 for(int k=-50; k<=50; k++) 30 { 31 if(i==0||j==0||k==0) 32 continue; 33 if(a1*i*i*i+a2*j*j*j+a3*k*k*k<0) 34 hash[a1*i*i*i+a2*j*j*j+a3*k*k*k+MAXN]++; 35 else 36 hash[a1*i*i*i+a2*j*j*j+a3*k*k*k]++; 37 } 38 39 for(int i=-50; i<=50; i++) 40 for(int j=-50; j<=50; j++) 41 { 42 int u=0-a4*i*i*i-a5*j*j*j; 43 if(u<0) 44 u=u+MAXN;; 45 if(hash[u]&&i!=0&&j!=0) 46 { 47 sum+=hash[u]; 48 } 49 } 50 printf("%d ",sum); 51 } 52 return 0; 53 }