HDOJ 1017 A Mathematical Curiosity

来源:互联网 发布:js如何清空div的内容 编辑:程序博客网 时间:2024/06/07 19:10
【题意】给出两个数n和m,计算这样的数对a和b。 0 < a < b < n and (a^2+b^2 +m)/(ab) 是一个整数。问题包含多组测试样例。第一行是一个整数N,然后一行包含在N个输入块中。每个输入块的形式在题目描述中已经说明。在两个输入块中包含一个空行。输入形式包含多个输出块,之间有空行。


注意:1. 判断一个数是整数的方法。2.整数、浮点数比较不要用==。3.格式是两个输出块之间有空行。

【代码:AC】

#include <iostream>#include <iomanip>#include <cstdlib>#include <cstdio>using namespace std;int main(){    //freopen("in.txt", "r", stdin);    //freopen("out.txt", "w", stdout);    int N = 0;    cin >> N;    while (N--)    {        int n = 0, m = 0, cas = 0;        int i = 0, j = 0;        while (cin >> n >> m && (n+m))        {            int cnt = 0;            cas++;            for (i = 0; i < n; i++)            {                for (j = i+1; j < n; j++)                {                    double temp1 = (i*i*1.0+j*j+m)/(i*j);                    int temp2 = temp1;                    if ((temp1-temp2) < 0.00001)                        cnt++;                }            }            cout << "Case " << cas << ": " << cnt << endl;        }        if (N!=0)            cout << endl;    }    return 0;}


0 0