2015年蓝桥杯省赛A组c++第1题

/*
方程: a^2 + b^2 + c^2 = 1000 
这个方程有整数解吗?有:a,b,c=6,8,30 就是一组解。 
你能算出另一组合适的解吗? 
请填写该解中最小的数字。 
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
*/


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
static int solution=0;
int main()
{
    for(int a=0;a<sqrt(1000);a++)
        for(int b=0;b<sqrt(1000);b++)
            for(int c=0;c<sqrt(1000);c++)
                if(pow(a,2)+pow(b,2)+pow(c,2)==1000){
                    solution++;
                    cout<<a<<","<<b<<","<<c<<","<<endl;
                }
    cout<<solution<<endl;
    return 0;
}

 

 

tz@COI HZAU

2018/3/14

 

posted on 2018-03-14 16:13  tuzhuo  阅读(188)  评论(0编辑  收藏  举报