PTA作业 求特殊方程的正整数解

#include<stdio.h>
#include<math.h>
int main()
{
    int n;
    int x,y;
    int count=0;
    scanf("%d",&n);
    y=2;
    x=1;

    for(x=1;x<100;x++)
    {
        for(y=2;y<100;y++)
        {
            if(x*x+y*y==n && x<=y)//x<=y避免重复解的情况
            {
                printf("%d %d\n",x,y);
                count++;//计数有几个解
            }
        }
    }
    if(count==0)
        printf("No Solution");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/jiangzenghui/p/12466442.html