天天看點

633. Sum of Square Numbers (Easy)兩數平方和

633. Sum of Square Numbers (Easy)兩數平方和

題目描述:判斷一個非負整數是否為兩個整數的平方和。

思路:利用判斷j是否是整數來判斷是否是兩個數的平方和。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
bool judgeSquareSum(int c){
    if(c<0)
        return false;
    for(long long int i = 0;i*i<=c;i++)
    {
        double j = sqrt(c - i*i);
        if(j == (int)j)
            return true;
    }
    return false;
}

int main(){
    int kk = judgeSquareSum(3);
    if(kk)
        printf("aa");
    else
        printf("bb");
    
   
    return 0;
}