1. 问题描述:
给定一个长度为 n 的整数数组 a1,a2,…,an。请你找出其中最大的不是完全平方数的数。如果一个整数 a 是某一个整数 b 的平方,那么这个整数 a 叫做完全平方数。
输入格式
第一行包含整数 n。第二行包含 n 个整数 a1,a2,…,an。
输出格式
一个整数,表示数组中的最大非完全平方数。保证一定有解。
数据范围
前三个测试点满足,1 ≤ n ≤ 10。
所有测试点满足,1 ≤ n ≤ 1000,−10 ^ 6 ≤ ai ≤ 10 ^ 6。
输入样例1:
2
4 2
输出样例1:
2
输入样例2:
8
1 2 4 8 16 32 64 576
输出样例2:
32
来源:https://www.acwing.com/problem/content/4006/
2. 思路分析:
分析题目可以知道模拟整个过程即可。
3. 代码如下:
import math
class Solution:
def process(self):
n = int(input())
res = -10 ** 8
a = list(map(int, input().split()))
for x in a:
if x < 0:
res = max(res, x)
continue
b = int(math.sqrt(x))
if b * b != x:
res = max(res, x)
return res
if __name__ == '__main__':
print(Solution().process())