UVA 6862 Triples 想法题

题目描述:

Mr. A invites you to solve the following problem:
“Let be m and n two positive integers, 5 ≤ m ≤ 100, 2 ≤ n ≤ 100. Consider the following sets of triples:
Tm.j = {(x, y, z) ∈ IN3 |x ≤ y ≤ z ≤ m and xj + yj = zj}, j = 2..n
where IN is the set of nonnegative integers (IN = {0, 1, 2, …}).”
The problem asks you to compute the sum Sm,n:
Sm,n =∑n j=2 card(Tm,j )
where card(Tm,j ) is the number of elements of the set Tm.j .
Input
The input file contains several test cases, each of them as described below.
The first line contains the value of m and the second line contains the value of n.
Output
For each test case, the result will be written to standard output, on a line by itself..
Sample Input

85
95

Sample Output

8128

题目分析:

求x^j+y^j=z^j有多少个
由费马大定理可以得,j>2的时候是无解的。所以我们只需要找m以内的勾股数和x为0时的n组数。

代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main()
{
    int m,n;
    int ii[100],jj[100],kk[100];
    int z=0;
    for(int i=3; i<=100; i++)
    {
        for(int j=i; j<=100; j++)
        {
            for(int k=j; k<=100; k++)
            {
                if(k*k==(i*i+j*j))
                {
                    ii[z]=i;
                    jj[z]=j;
                    kk[z++]=k;
                }
            }
        }
    }
    int data[120];
    memset(data,0,sizeof(data));
    for(int i=0; i<=100; i++)
    {
        for(int j=0; j<z; j++)
        {
            if(kk[j]<=i)
            {
                data[i]++;
            }
        }
    }
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        printf("%d\n",(n-1)*(m+1)+data[m]);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值