7-21 求特殊方程的正整数解 (15 分)

版权声明:SupremeBeast3_ https://blog.csdn.net/weixin_43359312/article/details/89069563

7-21 求特殊方程的正整数解 (15 分)

在这里插入图片描述
输入样例1:
884
输出样例1:
10 28
20 22
输入样例2:
11
输出样例2:
No Solution

AC代码

#include <stdio.h>
#include <math.h>
int main(){
    int X, Y, N;
    int ret = 0;
    scanf("%d", &N);
    for (X = 1; X < sqrt(N); X++){
        for (Y = 1; Y < sqrt(N); Y++)
            if (N == X*X + Y*Y && X <= Y){ printf("%d %d\n", X, Y); ret = 1; }
    }
    if (!ret) printf("No Solution\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43359312/article/details/89069563