本文共 1296 字,大约阅读时间需要 4 分钟。
模版题。
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 using namespace std;13 #define MOD 9777714 #define MAXN 100000015 struct node16 {17 int data;18 struct node *next;19 }*head[MOD],hash[MAXN];20 int cube(int x)21 {22 return x*x*x;23 }24 int main()25 {26 int i,j,k,a1,a2,a3,a4,a5,key,m,num = 0,ans = 0;27 scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);28 for(i = -50;i <= 50;i ++)29 {30 if(i == 0) continue;31 for(j = -50;j <= 50;j ++)32 {33 if(j == 0) continue;34 key = a1*cube(i) + a2*cube(j);35 node *p;36 p = &hash[num++];37 p -> data = key;38 key = key%MOD;39 if(key < 0)40 key += MOD;41 p -> next = head[key];42 head[key] = p;43 }44 }45 for(i = -50;i <= 50;i ++)46 {47 if(i == 0) continue;48 for(j = -50;j <= 50;j ++)49 {50 if(j == 0) continue;51 for(k = -50;k <= 50;k ++)52 {53 if(k == 0) continue;54 key = a3*cube(i) + a4*cube(j) + a5*cube(k);55 m = (-key)%MOD;56 if(m < 0) m += MOD;57 node *p;58 for(p = head[m];p != NULL;p = p->next)59 {60 if(p->data == -key)61 ans ++;62 }63 }64 }65 }66 printf("%d\n",ans);67 return 0;68 }
转载于:https://www.cnblogs.com/naix-x/archive/2013/01/15/2860720.html