タイトル基本的なプログラミングが正の整数の特別な方程式の7-21ソリューションを設定する(15分)

ここに画像を挿入説明

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int x = 0, y = 0, N = 0, flag = 0;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		for (x = 1; x <= 100; x++) {
			for (y = x; y <= 100; y++) { // 关于y定义域--x<=y<=100 的处理
				if (x * x + y * y == N) {
					flag = 1;
					System.out.println(x + " " + y);
					break;
				}
			}
		}
		if (flag == 0) {
			System.out.println("No Solution");
		}
		sc.close();
	}

}
公開された287元の記事 ウォンの賞賛117 ビュー8931

おすすめ

転載: blog.csdn.net/qq_44458489/article/details/105400093