如何分割数字x,其中x1是完美的正方形,我,e 50 = 49 + 1 直到结束 我尝试过:
how to split number x where x1 is perfect square and i,e 50=49+1 till end What I have tried:
#include <stdio.h> int main() { int a, n; printf("Enter a number: "); scanf("%d", &n); for(a = 0; a <= n; a++) { if (n == a * a) { printf("YES"); return 0; } } printf("NO"); return 0; }</stdio.h>推荐答案
首先查看问题: Start by looking at the problem: X = Y*Y + Z*Z, where X is a perfect square.
我可能首先要确定所有的完美的正方形小于X,然后开始寻找组合,取最大值,加上最低值,看看是否匹配。 如果确实如此,你就完成了。 如果它低于X,请尝试下一个最低值并重复。 如果它大于X,请尝试下一个最高值并重复。 如果Y == Z它不存在。 但这是你的作业,所以我不会给你任何代码!
I'd probably start by identifying all the perfect squares less than X, and then start looking for "combinations", by taking the largest, adding the lowest and seeing if it matches. If it does, you're done. If it's lower than X, try the next lowest and repeat. If it's greater than X, try the next highest and repeat. If Y==Z it doesn't exist. But this is your homework, so I won't give you any code!
更多推荐
如何分割数字x,其中x1是完美的正方形和i,e 50 = 49 + 1
发布评论