循环-13. 求特殊方程的正整数解

 1 /*
 2  * Main.c
 3  * C13-循环-13. 求特殊方程的正整数解
 4  *  Created on: 2014年8月1日
 5  *      Author: Boomkeeper
 6  ******测试通过******
 7  */
 8 
 9 #include <stdio.h>
10 #include <math.h>
11 
12 int main(void) {
13 
14     int x, y, N; //题目中的变量
15     int flag = 0; //如有实根,则标记为1,初始为0
16 
17     scanf("%d", &N);
18     //判断输入合法性
19     if (N < 2)
20         return 1;
21 
22     /*
23      * 为什么y = sqrt(N)-1就错了???
24      */
25     for (y = sqrt(N); y > 0; y--) {
26         for (x = 1; x <= y; x++) {
27             if ((x * x + y * y) == N) {
28                 printf("%i %i
", x, y);
29                 flag = 1;
30             }
31 
32         }
33     }
34     if (flag == 0)
35         printf("No Solution
");
36 
37     return 0;
38 }

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-13

      

原文地址:https://www.cnblogs.com/boomkeeper/p/C13.html