HDU 1017 A Mathematical Curiosity【看懂题意+穷举法】
//2014.10.17 01:19
//题意:
//先输入一个数N,然后分块输入,每块输入每次2个数,n,m,直到n,m同时为零时
//结束,当a和b满足题目要求时那么这对a和b就是一组
//注意:
//每一块的输出中间有一个回车
A Mathematical Curiosity
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.
1 10 1 20 3 30 4 0 0
Case 1: 2 Case 2: 4 Case 3: 5
#include<stdio.h> int main() { int N; int n,m; int a,b; int cas; scanf("%d",&N); while(N--) { cas=1; while(scanf("%d%d",&n,&m),n||m) { int count=0; for(a = 1; a < n; a++)//穷举法 { for(b = a + 1; b < n; b++) { if((a*a + b*b + m) % (a * b) == 0) count++; } } printf("Case %d: %d\n",cas++,count); } if(N) printf("\n"); } return 0; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。