算法:
1.分成两半部分,前面两个一组,后面三个一组。
2. HASH保存前两个数和,或二分查找。
View Code
#include<stdio.h> #include<string.h> #include<stdlib.h> #define MAXN 12500000 short int hash[26500000]; int a, b, c, d, e; int main( ) { while( scanf("%d%d%d%d%d", &a, &b, &c, &d, &e) != EOF) { int cnt = 0; memset(hash, 0, sizeof(hash)); for( int i = -50; i <= 50; i++) { if( i == 0 ) continue; for( int j = -50; j<= 50; j++) { if( j == 0 ) continue; hash[ a * i * i * i + b * j * j * j + MAXN]++; } } for( int i = -50; i <= 50; i++) { if( i == 0 ) continue; for( int j = -50; j <= 50; j++) { if( j == 0) continue; for( int k = -50; k <= 50; k++) { if( k == 0 ) continue; int ans = i * i * i * c + j * j * j * d + k * k * k * e; ans = -ans; if( ans < -12500000 ) { if( e < 0 && k > 0 ) break; continue; } else if( ans > 12500000 ) { if( e > 0 && k > 0) break; continue; } if( hash[ans+MAXN] ) cnt += hash[ans+MAXN]; } } } printf("%d\n",cnt); } return 0; }