1~100000 范围不算大,直接计算即可,否则要用到数论知识~
#include
#include
int isPerfectSquare(const long num);
int main(int argc, char const *argv[])
{
long l;
for (l = 1; l <=100000; ++l) {
if ( isPerfectSquare(l+100) && isPerfectSquare(l+168) )
printf(" %d", l);
}
return 0;
}
int isPerfectSquare(const long num)
{
long sr = (long)sqrt(num);
return (sr*sr == num);
}
运行结果:
156