HDU1496 Equations 卡时间第二题
2024-08-29 15:17:32
Consider equations having the following form:
a*x1^2+b*x2^2+c*x3^2+d*x4^2=0
a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.
It is consider a solution a system ( x1,x2,x3,x4 ) that verifies the equation, xi is an integer from [-100,100] and xi != 0, any i ∈{1,2,3,4}.
Determine how many solutions satisfy the given equation.
InputThe input consists of several test cases. Each test case consists of a single line containing the 4 coefficients a, b, c, d, separated by one or more blanks.
End of file.OutputFor each test case, output a single line containing the number of the solutions.
Sample Input
1 2 3 -4
1 1 1 1
Sample Output
39088
0
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<memory>
#include<map>
#include<cstring>
using namespace std;
int a,b,c,d;
int q[];
int main()
{
int i,j,k,ans;
while(cin>>a>>b>>c>>d){
ans=;
if(a>&&b>&&c>&&d>){
printf("0\n");
continue;
}
if(a<&&b<&&c<&&d<){
printf("0\n");
continue;
}
memset(q,,sizeof(q));
for(i=;i<=;i++)
for(j=;j<=;j++)
q[i*i*a+j*j*b+]++;
for(i=;i<=;i++)
for(j=;j<=;j++)
ans+=q[-i*i*c-j*j*d];
printf("%d\n",ans*);
}
return ;
}
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<memory>
#include<map>
using namespace std;
int a,b,c,d;
map<int,int>q;
int main()
{
int i,j,k,ans;
while(cin>>a>>b>>c>>d){
ans=;
if(a>&&b>&&c>&&d>||a<&&b<&&c<&&d<) //因为x那项永远是正数,如果系数都为正或者为负的时候明显不等于0
{
printf("0\n");
continue;
}
q.clear();
for(i=;i<=;i++)
for(j=;j<=;j++)
q[i*i*a+j*j*b]++;
for(i=;i<=;i++)
for(j=;j<=;j++)
ans+=q[-i*i*c-j*j*d];
printf("%d\n",ans*);
}
return ;
}
最新文章
- 李洪强iOS经典面试题129
- 指定线程执行的顺序---join()
- java break语句的三种用法
- su - root 报su: incorrect password的错误
- Model层数据验证
- 【转】Github入门教程
- SKProductsRequest ios 7不调用delegate
- hdu 4604 Deque(最长上升与下降子序列-能够重复)
- 第四篇:R语言数据可视化之折线图、堆积图、堆积面积图
- 定时且周期性的任务研究II--ScheduledThreadPoolExecutor
- 应对linux下的闰秒
- 纯css 构造的tip
- BZOJ3575 HNOI2014 道路阻塞
- Eclipse打jar包,资源文件的读取
- 查看电脑系统参数(Windows)
- javascript 之 第七章第三节(this关键字)
- jQuery图片自动添加水印插件
- Python学习—基础篇之基本数据类型(二)
- Primitives vs Objects
- Swap Nodes in Pairs LeetCode题解