http://poj.org/problem?id=1840
枚举 xi不等0.
View Code
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 #define MOD 97777 6 #define size 1000010 7 int t,head[size],next[size],v[size],num[size][2]; 8 void init() 9 { 10 t =0 ; 11 memset(head,-1,sizeof(head)); 12 } 13 void add(int a,int b) 14 { 15 next[t] = head[a]; 16 head[a] = t; 17 v[t] = b; 18 t++; 19 } 20 int main() 21 { 22 int i,j,k,a[6],s,g=0; 23 init(); 24 for(i = 1; i <= 5 ; i++) 25 cin>>a[i]; 26 for(i = -50; i <= 50 ;i++) 27 { 28 if(i==0) 29 continue; 30 for(j = -50; j <= 50 ; j++) 31 { 32 g++; 33 if(j==0) 34 continue; 35 s = a[1]*(i*i*i)+a[2]*(j*j*j); 36 s = s%MOD; 37 if(s<0) 38 s+=MOD; 39 num[g][0] = i; 40 num[g][1] = j; 41 add(s,g); 42 } 43 } 44 int sum = 0,o,ss; 45 for(i = -50 ; i <= 50 ; i++) 46 { 47 if(i==0) 48 continue; 49 for(j = -50 ; j <= 50 ; j++) 50 { 51 if(j==0) 52 continue; 53 for(k = -50 ; k <= 50 ; k++) 54 { 55 if(k==0) 56 continue; 57 s = a[3]*(i*i*i)+a[4]*(j*j*j)+a[5]*(k*k*k); 58 ss = s; 59 s = (-s)%MOD; 60 if(s<0) 61 s += MOD; 62 for(o = head[s] ; o!=-1 ; o = next[o]) 63 { 64 int i1 = num[v[o]][0],i2 = num[v[o]][1]; 65 if((a[1]*(i1*i1*i1)+a[2]*(i2*i2*i2))==-ss) 66 sum++; 67 } 68 } 69 } 70 } 71 cout<<sum<<endl; 72 return 0; 73 }