pythonExample100/JCP003.py

27 lines
756 B
Python
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序3】
题目一个整数它加上100后是一个完全平方数再加上168又是一个完全平方数请问该数是多少
1.程序分析在10万以内判断先将该数加上100后再开方再将该数加上268后再开方如果开方后
      的结果满足如下条件,即是结果。请看具体分析:
2.程序源代码:
#include "math.h"
main()
{
long int i,x,y,z;
for (i=1;i<100000;i++)
 { x=sqrt(i+100);   /*x为加上100后开方后的结果*/
  y=sqrt(i+268);   /*y为再加上168后开方后的结果*/
   if(x*x==i+100&&y*y==i+268)/*如果一个数的平方根的平方等于该数,这说明此数是完全平方数*/
    printf("\n%ld\n",i);
 }
}
'''
import math
for i in range(10000):
#转化为整型值
x = int(math.sqrt(i + 100))
y = int(math.sqrt(i + 268))
if(x * x == i + 100) and (y * y == i + 268):
print i