四平方和定理

输入一个n使a*a+b*b+c*c+d*d==n,a<=b<=c<=d

 

/*
三次递归abc来求出d

*/

#include <iostream> #include <cstdio> #include <cmath> using namespace std; int n; int main() { ios::sync_with_stdio(false); cin>>n; for(int a=0;a<=sqrt(n/4);++a) { for(int b=a;b<=sqrt(n/3);++b) { for(int c=b;c<=sqrt(n/2);++c) { for(int d=c;a * a + b * b + c * c + d * d <= n;++d) { if(a*a+b*b+c*c+d*d==n){ printf("%d %d %d %d\n",a,b,c,d); return 0; } } } } } return 0; }

 

posted @ 2018-07-19 16:10  Somnus、M  阅读(236)  评论(0编辑  收藏  举报