poj 1840 Eqs

来源:互联网 发布:三大会计软件 编辑:程序博客网 时间:2024/06/04 18:05

Eqs
Time Limit: 5000MS Memory Limit: 65536KTotal Submissions: 11861 Accepted: 5808

Description

Consider equations having the following form: 
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

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
     

题目意思:

给你a1 , a2 , a3 , a4 , a5  求方程a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 

的解的个数 已知 x1 x2 x3 x4 x5 都不等于 0

若是直接用暴力来写的话,100的五次方肯定会T掉,所以先求前三个a1x13+ a2x23+ a3x33

的值用数组a[100008][100]存起来 (这里为什么是100008因为mod100007)(还有就是为什么是100最开始写的是10导致一直WA原因就是10可能不够存mod值相同的个数)

用数组top[100008]表示哈希%mod之后的值的个数

#include<iostream>#define mod 100007;#include<cstring>int a[100008][100];int top[100008];using namespace std;int main (){    int a1,a2,a3,a4,a5;    int x1,x2,x3,x4,x5;    int sum1,sum2;    int ans=0;    memset(top,0,sizeof(top));    cin>>a1>>a2>>a3>>a4>>a5;    for(x1=-50;x1<=50;x1++)    {        if(x1==0) continue;        for(x2=-50;x2<=50;x2++)        {            if(x2==0) continue;            for(int x3=-50;x3<=50;x3++)            {                if(x3==0) continue;                sum1=a1*x1*x1*x1+a2*x2*x2*x2+a3*x3*x3*x3;                int p=sum1;                p=p%mod;                if(p<0) p+=mod;                a[p][top[p]++]=sum1;            }        }    }    for(x4=-50;x4<=50;x4++)    {        if(x4==0) continue;        for(x5=-50;x5<=50;x5++)        {            if(x5==0) continue;            sum2=-a4*x4*x4*x4-a5*x5*x5*x5;            int p=sum2;            p=p%mod;            if(p<0) p+=mod;            for(int i=0;i<top[p];i++)            {                if(a[p][i]==sum2) ans++;            }        }    }    cout<<ans<<endl;}




0 0
原创粉丝点击