5-21 求特殊方程的正整数解

本题要求对任意给定的正整数N,求方程X2+Y2=N的全部正整数解。

输入格式:

输入在一行中给出正整数N10000)。

输出格式:

输出方程X2+Y2=N的全部正整数解,其中XY。每组解占1行,两数字间以1空格分隔,按X的递增顺序输出。如果没有解,则输出No Solution

输入样例1:

884

输出样例1:

10 28
20 22

输入样例2:

11

输出样例2:

No Solution

#include <stdio.h>
#include <stdbool.h>
#include <math.h>

int main(void)
{
	int x, y;
	int N;
	scanf("%d", &N);
	bool result = false;
	for (x = 0; x<sqrt(N/2); x++)
		for (y = 0; y<sqrt(N); y++)
			if ((x*x + y*y )== N)
			{
		<span style="white-space:pre">		</span>printf("%d %d\n", x, y);
	      <span style="white-space:pre">			</span>result = true;
			}

	if (!result)
		printf("No solution\n");

	return 0;
}


你可能感兴趣的:(C语言,PTA基础编程题目集)