zcmu-1281 Mathematical Curiosity(暴力)

Description

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.

Input

You 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.

Output

For 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 Input

10 1 20 3 30 4 0 0

Sample Output

Case 1: 2 Case 2: 4 Case 3: 5

数字不大,直接暴力过就行

#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 1e6 + 5;
int dp[maxn],a[maxn];
int main() {
    int n,m,t = 0;
    while(scanf("%d%d",&n,&m) != EOF )
    {
        if(n == 0 && m == 0)
            break;
        t++;
        int count = 0;
        for(int i = 1; i < n; i++)
        {
            for(int  j = i + 1; j < n ;j++)
            {
                double x = (i*i + j*j + m)/(i*j*1.0);
                //printf("%.1lf\n",x);
                if(x - (int)x == 0)
                    count ++;
            }
        }
        cout<<"Case "<<t<<": "<<count<<endl;
    }
    
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hzyhfxt/article/details/82014597