杭电acm1017题 感觉代码没错,但就是ac不了,我无解了,求教啊啊啊啊!!!
题目是这样的:Giventwointegersnandm,countthenumberofpairsofintegers(a,b)suchthat0<a<b<nand(a...
题目是这样的:Given two integers n and m, count the number of pairs of integers (a,b) such that 0 < a < b < n and (a^2+b^2 +m)/(ab) is an integer.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
InputYou will be given a number of cases in the input. Each case is specified by a line containing the integers n and m. The end of input is indicated by a case in which n = m = 0. You may assume that 0 < n <= 100.
OutputFor each case, print the case number as well as the number of pairs (a,b) satisfying the given property. Print the output for each case on one line in the format as shown below.
Sample Input1
10 1
20 3
30 4
0 0
Sample OutputCase 1: 2
Case 2: 4
Case 3: 5我的代码:#include<stdio.h>
int main()
{int n,m,i,j,x,a,z=0;
scanf("%d",&x);
printf("\n");
for(a=1;a<x+1;a++)
{scanf("%d %d",&n,&m);
printf("\n");
if(!((n==m)&&(n==0)))
{z=0;
for(i=1;i<n;i++)
for(j=i+1;j<n;j++)
if(((i*i+j*j+m)%(i*j))==0)
z++;
printf("Case %d: %d\n",a,z);}
else break;}return 0;
} 展开
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
InputYou will be given a number of cases in the input. Each case is specified by a line containing the integers n and m. The end of input is indicated by a case in which n = m = 0. You may assume that 0 < n <= 100.
OutputFor each case, print the case number as well as the number of pairs (a,b) satisfying the given property. Print the output for each case on one line in the format as shown below.
Sample Input1
10 1
20 3
30 4
0 0
Sample OutputCase 1: 2
Case 2: 4
Case 3: 5我的代码:#include<stdio.h>
int main()
{int n,m,i,j,x,a,z=0;
scanf("%d",&x);
printf("\n");
for(a=1;a<x+1;a++)
{scanf("%d %d",&n,&m);
printf("\n");
if(!((n==m)&&(n==0)))
{z=0;
for(i=1;i<n;i++)
for(j=i+1;j<n;j++)
if(((i*i+j*j+m)%(i*j))==0)
z++;
printf("Case %d: %d\n",a,z);}
else break;}return 0;
} 展开
2个回答
展开全部
/*不知道你为什么觉得你的代码没有问题,连测试样例都没过。
题目中是第一行输入有几组测试数据,这个组不是case,而是每个0 0标志一组结束
下面是根据你代码修改AC后的结果,不懂可追问:
*/
#include<stdio.h>
int main()
{
int n,m,i,j,x,a,z=0,c;
scanf("%d",&x);
for(a=1;a<x+1;a++)
{
if (a>1) printf("\n");
c = 0;
while(++c)
{
scanf("%d %d",&n,&m);
if(!((n==m)&&(n==0)))
{
z=0;
for(i=1;i<n;i++)
for(j=i+1;j<n;j++)
if(((i*i+j*j+m)%(i*j))==0)
z++;
printf("Case %d: %d\n",c,z);
}
else break;
}
}
return 0;
}
题目中是第一行输入有几组测试数据,这个组不是case,而是每个0 0标志一组结束
下面是根据你代码修改AC后的结果,不懂可追问:
*/
#include<stdio.h>
int main()
{
int n,m,i,j,x,a,z=0,c;
scanf("%d",&x);
for(a=1;a<x+1;a++)
{
if (a>1) printf("\n");
c = 0;
while(++c)
{
scanf("%d %d",&n,&m);
if(!((n==m)&&(n==0)))
{
z=0;
for(i=1;i<n;i++)
for(j=i+1;j<n;j++)
if(((i*i+j*j+m)%(i*j))==0)
z++;
printf("Case %d: %d\n",c,z);
}
else break;
}
}
return 0;
}
追问
其实我题目就不怎么懂,不明白已经用一个数来控制测试数量了为什么还要用0 0 控制测试结束
追答
第一个数是控制测试数据组数的,每组以0 0做结尾。
例子给的是n=1的情况,如果n>1的话可以是这样:
2
20 3
30 4
0 0
10 1
40 5
60 8
0 0
n是控制0 0的个数,0 0是每一组的结束符。
北京康思
2018-09-20 广告
2018-09-20 广告
1、基本功能。市面上的电子负载均有基本的四项功能:恒流、恒压、恒阻和恒功率(安捷伦没有恒功率)。在功能基本相同,精确度相差不大的情况下,怎么判断是否符合要求呢?CHROMA和博计的电子负载只有一套工作电路,就是恒流功能。其他功能是根据欧姆定...
点击进入详情页
本回答由北京康思提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询