考试的最后一题。。又是数学题。。。(又是宛如智障)
x2+y2=z2
可以有:
x=a2−b2
y=2ab
z=a2+b2
然后直接预处理 = = 、
哎!;
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef long long LL;
const int N=1e6+10;
struct asd{
LL a,b,c;
}ans[N],q[N];
int ans_num;
LL num;
bool cmp(asd x,asd y)
{
if(x.a == y.a){
if(x.b == y.b) return x.c < y.c;
return x.b < y.b;
}
return x.a < y.a;
}
void init(){
LL x,y,z;
ans_num = 0;
for(LL i=2;i<=1000000;i++){
for(LL j = 1;j < i;j++){
x = i * i - j * j;
y = 2LL * i * j;
z = i * i + j * j;
if(z > 1000000) break;
if(__gcd(x, __gcd(y, x)) != 1) continue;
if(x > y) swap(x, y);
ans[ans_num].a = x;
ans[ans_num].b = y;
ans[ans_num].c = z;
ans_num++;
}
}
sort(ans, ans+ans_num,cmp);
}
LL n,Left, Right;
int main(){
init();
while(~scanf("%lld%lld%lld",&n,&Left,&Right)){
num = 0;
for(int i=0;i<ans_num;i++){
if(ans[i].c <= n){
num++;
q[num] = ans[i];
}
}
sort(q+1,q+num+1,cmp);
if(Left>num){
puts("0");
}
else{
int cas=1;
num = min(num, Right);
printf("%d\n",num - Left + 1);
for(int i=Left;i <= num;i++)
printf("Case: %d a=%lld,b=%lld,c=%lld\n",cas++,q[i].a,q[i].b,q[i].c);
}
}
return 0;
}