一個整數,加上100後是一個完全平方數,再加上168,還是一個完全平方數,找出三個這樣的數

#include "iostream"
#include <cmath>
using namespace std;


int main()
{
    int i=0;    //用於窮舉
    int count =0;   //用於計數
    while(1)
    {

        double temp1 = i+100;
        double temp2 = i+100 +168;
        if(sqrt(temp1)*sqrt(temp1) == temp1 && sqrt(temp2)*sqrt(temp2) == temp2)  // sqrt(9)*sqrt(9) = 9;
        {
            count++;    //找到一個計數加1
            cout<<i <<endl;
        }

        if(count == 3)
        {
            break;
        }
        i++;

    }

    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章