UVALive 6862——结论题&&水题

题目

链接

题意:求满足$0 leq x leq y leq z leq m$且$x^j + y^j = z^j, j=2 cdots n$的三元组的对数

分析

由费马大定理:整数$n >2$时,关于$x, y, z$的方程  $x^n + y^n = z^n$ 没有正整数解。

因此,我们只需考虑$j=2$的情况。对于$j>2$时,只存在$x=0, y=z$的解.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 typedef long long ll;
 5 int m, n;
 6 
 7 int  main()
 8 {
 9     while(scanf("%d%d", &m, &n)==2)
10     {
11         int ans = 0;
12         for(int i = 0;i <= m;i++)
13         for(int j = i;j <= m;j++)
14         {
15             //if(i + j <= m)  ans++;
16             int z = sqrt(i * i + j * j);
17             if(z * z == (i*i + j*j) && z <= m && z >= j) ans++;
18         }
19         printf("%d
", ans + (n-2)*(m+1));
20     }
21     return 0;
22 }
原文地址:https://www.cnblogs.com/lfri/p/11181780.html